1. View available Redis versions

Search for redis image repository in Docker Hub. Here we use redis: 6.2-RC-alpine

  1. Write the docker-comemage. ym file
version: "3"

services:
  redis-singleton:
    container_name: redis-singleton
    image: Redis: 6.2 - rc - alpine
    ports:
      - "6379:6379"
    volumes:
      - ./data/master:/data
      - ./conf/redis.conf:/usr/local/etc/redis/redis.conf
    command: redis-server /usr/local/etc/redis/redis.conf
Copy the code

Here we hang a data directory and a configuration file, and then use comand command to override the container startup command, let redis-server start up to load our configuration file

  1. Start theredisservice

Run the up command to build and start the container

$ docker-compose up -d
Copy the code
  1. Into the container

Use the Docker exec command to enter the container and test whether the Redis service starts properly

$docker exec -it redis-singleton /bin/sh /data # redis-cli 127.0.0.1:6379> set foo bar OKCopy the code

Note that /bin/sh is used, not /bin/bash, because this mirror only has the sh terminal

If you like, I can search the official accounthuangxyFollow me or scan the QR code below