Ensure that Docker is installed in your system. Follow Docker's installation guide if you haven’t installed it yet
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.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
241f2411637e redis "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 6379/tcp myredis
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
Execute the following command to test the Redis server:
127.0.0.1:6379>ping
PONG
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