Recently, I changed to a new computer, so I didn’t want to configure the environment one by one, so I wanted to use Docker to create a one-click configuration environment. But I have never touched Docker before, so I will write an article to record the configuration process, so as not to forget later
Dockerfile write
Because the protected mode is enabled by default in Redis, it can only be accessed in the local environment. To disable this mode, you need to customize some redis
Redis. IO /redis-stabl… , modify the following places:
- Bind # comment out
- Protected -mode # change true to false
- Requirepass # configures the password of redis
- Daemonize # will be yes then change to no
Write a Dockerfile referencing the redis. Conf file edited above
FROM redis
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server"."/usr/local/etc/redis/redis.conf" ]
Copy the code
Create a mirror image
Create an image based on the Dockerfile above
docker build -t <your name>/redis .
Copy the code
Create a container
To generate a container based on the image above, run the -p command to map the port to the local port
docker run -itd --name redis -p 6379:6379 <your name>/redis
Copy the code
If you want to persist data, add the — appendOnly Yes parameter