First, install the Docker environment.

Then configure the docker image source as a domestic image to improve the pull speed.

Docker daemon.json

cat /etc/docker/daemon.json
Copy the code

Added Ali mirror source library:

vim /etc/docker/daemon.json
Copy the code

Content as follows:

{
    "insecure-registries": ["192.168.107.51:5000"]."registry-mirrors": ["https://mltfzuzk.mirror.aliyuncs.com"]."dns": ["8.8.8.8"."8.8.4.4"]}Copy the code

Where: insecure-registries is the docker private warehouse address. No Docker repository can be used without configuration.

If daemon.json is abnormal, restarting docker will prompt Job…… Exception at the beginning.

If you are prompted that vim is not available, install vim:

yum -y install vim-enhanced
Copy the code

Modify daemon.json to make the configuration take effect:

sudo systemctl daemon-reload
Copy the code

Restart the docker:

sudo systemctl restart docker
Copy the code

After normal startup, it can be useddocker versionView the Docker version information.

Install mysql 5.7.24

Pull mysql image

Docker pull mysql: 5.7.24Copy the code

After the pull is successful, you can view the local Docker image using Docker images.

Pull redis image, pull the latest version directly:

docker pull redis
Copy the code



Install mysql, map port, mount directory:

Docker run --restart always \ --name mysql.5.7.24 \ -p 3306:3306 \ -v /usr/soft/mysql-3306/data:/var/lib/mysql \ -v /usr/soft/mysql-3306/conf.d:/etc/mysql/conf.d \ -v /usr/soft/mysql-3306/etc.mysql:/etc/mysql \ -e MYSQL_ROOT_PASSWORD = 123456 \ - d mysql: 5.7.24Copy the code

View the mount directory:

Docker inspect mysql. 5.7.24 | grep Mounts - A 20Copy the code

Redis installation:

docker run --restart=always \
	--name redis \
	--privileged=true \
	-p 6379:6379 \
	-v /etc/localtime:/etc/localtime \
	-v /usr/soft/redis/redis.conf:/etc/redis/redis.conf \
	-v /usr/soft/redis/data:/data \
	-d redis redis-server /etc/redis/redis.conf \
	--appendonly yes \
	--requirepass "123456 @ 2021" 
Copy the code

Parameter Description:

– ring = true: the root container with real root, otherwise container root just outside the ordinary user permissions – v/usr/soft/redis/redis. Conf: / etc/redis/redis conf: Mapping configuration file – v/usr/soft/redis/data: / data: mapping the data catalogue redis server/etc/redis/redis conf: specify the configuration file to start the redis – server process – appendonly yes: Enable data persistence

Customize the contents of the redis.conf file:

Redis. Conf is commented out with the following modificationsbind 127.0.0.1   # comment out this section. This limits redis to local access onlyComment daemonize noThe default no #Change protected-mode to noCopy the code

If the container is not specified when it is started, it automatically restarts. You can use the following command:

Docker update application image name --restart=alwaysCopy the code

At this point, mysql and Redis are ready to use. You may notice that there is no change to the server firewall or port, isn’t it amazing?

If you change the ports of the firewall or restart the firewall, you need to enable ports 3306 and 2379 separately. By default, the container should automatically add iptables mapping rules when the two images are started. However, the port mapping is based on the rules of the dockerId mapping, and these rules are invalid after the firewall is restarted. Therefore, the connection between mysql and Redis fails.

To view the list of open ports, run firewall-cmd –list-ports

Open ports 3306 and 6379:

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=6379/tcp --permanent
Copy the code

The firewall takes effect only after being restarted:firewall-cmd --reload