Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Docker Compose Redis server and client

version: '3.8'
services:
  client:
    build: .
    volumes:
    - .:/opt
    links:
    - redis
    command: tail -f /dev/null
  redis:
    image: redis:latest
FROM ubuntu:23.04
RUN apt-get update && \
    apt-get install -y curl && \
    apt-get install -y redis-tools

Start the docker containers

docker-compose up -d

Connect to the docker container which has the redis client:

docker exec -it redis_client_1 bash

Try the following commands in the Docker container:

redis-cli -h redis get name
(nil)

redis-cli -h redis set name Foobar
OK


redis-cli -h redis get name
"Foobar"

We provide the hostname redis because that's the name of the service. We don't have to provide the port, but if you'd really want to then try this:

redis-cli -h redis -p 6379 get name