The process of Docker building Redis5.0 and mounting data was recorded, and the building reference was from Docker Hub

Series welcome to visit: www.itwxe.com/posts/9e76d.

First, simply mount persistent data

Docker run - d - p - 6379-6379 the name redis \ - v/itwxe/dockerData/redis/data: / data \ redis: 5.0.8 redis - server - appendonly yesCopy the code

Redis has no password or other configuration. Anyone can connect. If the server is on the public network, it is extremely insecure.

The redis.conf file does not exist in the container. The redis.conf file is not found in the container.

As mentioned in Docker Hub, you need to customize redis.conf to build images using DockerFile.

Build image through DockerFile, specify configuration file to start

1. Go to the official website of Redis to get the same version as the image version (my version is 5.0.8), then unzip the file and upload the redis.conf file to the server.

2. Modify the redis.conf configuration. The main configuration is as follows.

# Change background startup to daemonize no, docker start by default Daemonize no # How long the client has been idle before disconnecting, default is 0 Disable this feature timeout 0 # Set password, default is commented, Uncomment and change to a custom password (mine was 123456) requirePass 123456 # listening IP, allowed IP, default is 127.0.0.1, Change the value to 0.0.0.0(allow access to all server IP addresses) or comment out bind 0.0.0.0 # to specify the listening port, default is 6379, here I leave the default port 6379 # with AOF persistence enabled. # change AOF and RBD to /data dir /data # Change log to "", Change to "/data/redis_6379.log" logfile "/data/redis_6379.log"Copy the code

3, create Dockerfile file, add content, do not know how to use Dockerfile how to use can see Dockerfile build image.

FROM redis:5.0.8
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD ["redis-server"."/usr/local/etc/redis/redis.conf"]
Copy the code

4. Create a mirror.

Docker build -t itWxe /redis:5.0.8.Copy the code

5. Start the image and mount the data.

Docker run - d - p - 6379-6379 the name redis \ - v/itwxe/dockerData/redis/data: / data \ itwxe/redis: 5.0.8Copy the code

You can see that the data is mounted properly.

At the same time can test the password can also connect normally.

Now that you’ve read this, like, comment, follow, or collect it!

Author: IT wang2 xiao3 er4 starting address: www.itwxe.com/posts/7fbf9… Copyright notice: the content of the article is subject to the authorship-non-commercial-no deduction 4.0 international license, except for special notice, all original, reprint please give the author and the original link in the obvious position of the article page.