Let's create a temporary directory for our install and setup of Redis.
mkdir /tmp/redis
And move into the directory.
cd /tmp/redis
Let's create a file named Dockerfile.
touch Dockerfile
And let's add the following to the Dockerfile to pull down the latest redis image.
FROM redis
And then use the docker build command to pull down the latest redis image.
~]$ sudo docker build --tag redis:latest .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM redis
latest: Pulling from library/redis
b0a0cf830b12: Pull complete
214d0afb35ca: Pull complete
16a9d12e7a2c: Pull complete
cb9709829e8b: Pull complete
00e912971fa2: Pull complete
f7ebca356832: Pull complete
4f4fb700ef54: Pull complete
c16c264be546: Pull complete
Digest: sha256:f14f42fc7e824b93c0e2fe3cdf42f68197ee0311c3d2e0235be37480b2e208e6
Status: Downloaded newer image for redis:latest
---> 9509c4dd19fb
Successfully built 9509c4dd19fb
Successfully tagged redis:latest
The docker images command should now return the latest redis image.
~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 9509c4dd19fb 3 weeks ago 116MB
Let's use the docker run command to create and start a Redis container using the latest redis image.
~]$ sudo docker run --detach --name redis --publish 0.0.0.0:6379:6379 redis:latest
4cf2570d0f8f6ae2b5870590adbfb1e9977d74375c02a9e31c5e1bf182253dd0
The docker container ls command should now show the redis container is up and running.
~]$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4cf2570d0f8f redis:latest "docker-entrypoint.s…" 50 seconds ago Up 49 seconds 0.0.0.0:6379->6379/tcp redis
And the docker logs command should return something like this.
]$ sudo docker logs redis
1:C 30 Apr 2024 08:42:25.321 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:C 30 Apr 2024 08:42:25.321 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 30 Apr 2024 08:42:25.321 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 30 Apr 2024 08:42:25.321 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 30 Apr 2024 08:42:25.322 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1:M 30 Apr 2024 08:42:25.322 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 30 Apr 2024 08:42:25.322 # Current maximum open files is 1024. maxclients has been reduced to 992 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 30 Apr 2024 08:42:25.322 * monotonic clock: POSIX clock_gettime
1:M 30 Apr 2024 08:42:25.322 * Running mode=standalone, port=6379.
1:M 30 Apr 2024 08:42:25.323 * Server initialized
1:M 30 Apr 2024 08:42:25.323 * Ready to accept connections tcp
The docker exec command can be used to run the redis-cli command in the container.
~]$ sudo docker exec redis redis-cli --version
redis-cli 7.2.4
You can list the keys in the cache.
~]$ sudo docker exec redis redis-cli --scan
flask_cache_/foo
Did you find this article helpful?
If so, consider buying me a coffee over at