Documentation

How to Deploy and Run Redis in a Docker Container

Prerequisites#

Ensure that Docker is installed in your system. Follow Docker's installation guide if you haven’t installed it yet

Step 1: Run the Redis container#

Execute the following command to run Redis container in the background in a “detached” mode.

$ docker run --name myredis -d redis

where myredis is the name of Docker container -d representis running Redis in a background in a “detached” mode. redis is the name of Docker image that it fetches from Docker Hub.

Step 2: Verify that the Redis container is running#

$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS      NAMES
241f2411637e   redis     "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   6379/tcp   myredis

Step 3: Connect to your database#

The following uses the first three alphanumeric characters of your Container ID and opens up sh shell of the Redis Docker container:

$ docker exec -it 241 sh
# redis-cli

Step 4: Testing Redis container​#

Execute the following command to test the Redis server:

127.0.0.1:6379>ping
PONG

Step 5: Running Redis container with Persistent Storage#

In order to enable persistence, you should invoke the Docker container, passing appendonly yes option as shown below:

$ docker run --name some-redis -d redis redis-server --appendonly yes

If persistence is enabled, data is stored in the volume /data, which can be used with --volumes-from some-volume-container or -v /docker/host/dir:/data