1. Search for Redis images on Docker Hub

  2. Find the corresponding version in Tags, copy the command, and execute it

    Docker pull redis: 5.0.10Copy the code
  3. Start the basic service instance

    Docker run -p host port :6379 --name Container name -d redis:5.0.10Copy the code
  4. Enable Redis AOF persistence

    There are two types of Redis persistence, of which snapshot persistence is enabled by default. Docker officially believes that Redis snapshot persistence is useless, so there is no Description of snapshot persistence in Description, and dump. RDB file is also not in Redis.

    AOF persistence is officially provided.

    Docker run -p host port :6379 --name Container name -d redis:5.0.10 redis-server --appendonly yesCopy the code
  5. Query the appendone. aof file location

    When AOF is enabled, Redis generates an appendone.aof persistent file and we need to find its path in the container: /data

  6. Data volumes are used to persist data to the host machine

    The appendone.aof persistent file needs to be persisted to the host:

    Docker run -p host port :6379 --name Container name -d -v Volume name :/data redis:5.0.10 redis-server --appendonly yesCopy the code
  7. If you want to modify the Redis profile, make Redis run according to the new profile

    The Redis image does not contain the redis.conf configuration file. All the default configuration information is stored in the redis-sever command.

    There are two solutions:

    • Dockerfile

      FROM redis
      COPY redis.conf /usr/local/etc/redis/redis.conf
      CMD [ "redis-server"."/usr/local/etc/redis/redis.conf" ]
      Copy the code
    • Get the configuration file from the redis-5.0.10.tar.gz package and upload it to a directory on the host machine

      The access IP address specified in redis.conf can only be 127.0.0.1, so you need to modify the redis.conf configuration file

      Conf in the host and /usr/local/etc/redis in the container

      When finally start Redis, need after Redis – server command add/usr/local/etc/Redis/Redis conf, Redis will go to load at startup Redis. Configuration information in the conf.

      Docker run -p host port :6379 --name container name -d -v redis. Conf Host directory :/usr/localThe/etc/redis redis: 5.0.10 redis server/usr /local/etc/redis/redis.conf
      Copy the code

      Instead of having to get the complete configuration file, I’ll create a file called “bind 0.0.0.0” and replace the path to the file with “redis. Conf in the host directory “.

      At present, many images provided in Docker do not carry configuration files, so we only need to create a separate file and write the configuration to the file according to the original format. The file name can be customized. You only need to provide the path of the file, and the configuration in the file will automatically override the original configuration information.