Home > docker, python > docker-redis


You want to build a docker image with a Redis server in it. When you launch it, you want it to function as a redis server.

Dockerfile, build, run


# Redis
# VERSION       0.1

# use the ubuntu base image provided by dotCloud
FROM ubuntu

#MAINTAINER Jabba Laci, jabba.laci@gmail.com

# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update

# install redis
RUN apt-get install -y redis-server

# Launch redis-server when launching the container
ENTRYPOINT ["redis-server"]

# expose redis-server port


$ docker build -t redis .

Here I suppose that the file Dockerfile is in the current dorectory.


$ docker run -d -p 6379 redis

Run it in the background (-d) and expose its port 6379 to the host (-p).

Try it

docker ps will tell you the necessary port numbers:

$ docker ps

Meaning: the port 49163 on the host is redirected to the container’s port 6379. That is, if we want to connect to the redis-server in the container, we can do it through the host’s port 49163.

Of course, in your case it will be something else instead of port number 49163…

Test code:

>>> import redis
>>> r = redis.Redis('localhost', 49163)
>>> r.info()
{'pubsub_channels': 0, 'aof_enabled': 0, 'bgrewriteaof_in_progress': 0, 'connected_slaves': 0, 'uptime_in_days': 0, 'multiplexing_api': 'epoll', 'lru_clock': 558312, 'last_save_time': 1389703273, 'redis_version': '2.2.12', 'redis_git_sha1': 0, 'loading': 0, 'connected_clients': 1, 'keyspace_misses': 0, 'used_memory': 798784, 'vm_enabled': 0, 'used_cpu_user_children': 0.0, 'role': 'master', 'total_commands_processed': 0, 'used_memory_rss': 1662976, 'total_connections_received': 1, 'pubsub_patterns': 0, 'used_cpu_sys': 0.03, 'used_memory_human': '780.06K', 'used_cpu_sys_children': 0.0, 'blocked_clients': 0, 'used_cpu_user': 0.02, 'use_tcmalloc': 0, 'client_biggest_input_buf': 0, 'arch_bits': 64, 'redis_git_dirty': 0, 'expired_keys': 0, 'hash_max_zipmap_entries': 512, 'evicted_keys': 0, 'bgsave_in_progress': 0, 'client_longest_output_list': 0, 'hash_max_zipmap_value': 64, 'process_id': 1, 'uptime_in_seconds': 167, 'changes_since_last_save': 0, 'mem_fragmentation_ratio': 2.08, 'keyspace_hits': 0}
>>> # r.info() worked, so it's OK
>>> r.set('Jabba', 'the Hutt')
>>> r.get('Jabba')
'the Hutt'
Categories: docker, python Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: