Record the installation steps of Docker MySQL for the local virtual machine

After the local virtual machine installs the Docker environment, execute the ...

After the local virtual machine installs the Docker environment, execute the

Docker run - ITD -- name taoqiansheng-mysql5.7 - V / opt / data / MySQL /: / var / lib / MySQL - P 3306:3306 - e MySQL ﹐ root ﹐ password = admin123 - D MySQL: 5.7 command, Download MySQL image from official warehouse,

In this way, we create a MySQL database server container instance named taoqiansheng-mysql5.7, and mount the opt/data/mysql / directory to the MySQL container just created and started. Later, the MySQL data will be stored in this directory. When the database is created, the root password of the database is set through the environment variable MySQL ﹣ root ﹣ password, and the image version used is specified through the 5.7 label.

Problems encountered:

1. After corresponding port, it is found that the virtual machine cannot access port 3306 outside

Solution: View firewall

systemctl status firewalld

Shown below

firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-02-06 21:41:59 PST; 1 day 4h ago Docs: man:firewalld(1) Main PID: 708 (firewalld) Tasks: 2 Memory: 596.0K CGroup: /system.slice/firewalld.service └─708 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid Feb 06 21:53:02 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (d...at chain?). Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D OUTPUT -m addrtype --dst-type LOCAL -j DOCKER' failed: iptabl... that name. Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D PREROUTING' failed: iptables: Bad rule (does a matching rule ...at chain?). Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D OUTPUT' failed: iptables: Bad rule (does a matching rule exis...at chain?). Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -X DOCKER' failed: iptables: Too many links. Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -X DOCKER-ISOLATION-STAGE-1' failed: iptables: Too many links. Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -F DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name. Feb 06 21:58:08 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -X DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name. Feb 06 21:58:09 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (d...at chain?). Feb 06 21:58:09 localhost.localdomain firewalld[708]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (d...at chain?). Hint: Some lines were ellipsized, use -l to show in full.

My display shows that the firewall is on. If it is not, it needs to be executed:

systemctl start firewalld

Open 3306 port, open port syntax command is as follows: enable regional port and protocol combination

firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]

Here we need to open port 3306 and execute the following command

firewall-cmd --zone=public --add-port=3306/tcp --permanent

Here, the -- permanent parameter is used to make the startup permanent. If there is no such parameter, it will become invalid after restarting

After opening the port, you need to restart the firewall, execute the following command, and reload the firewall configuration

firewall-cmd --reload

I thought it would be OK. As a result, I didn't pay attention to the prompt when starting the container

WARNING: IPv4 forwarding is disabled. Networking will not work.

This question is also a reference

Docker error WARNING: IPv4 forwarding is disabled. Networking will not work

Solved

Download start operation reference of MySQL container: The use of MySQL official Docker image

Record it for future use

Er Yu Xi Published 1 original article, praised 0 and visited 2513 Private letter follow

8 February 2020, 07:53 | Views: 2365

Add new comment

For adding a comment, please log in
or create account

0 comments