The installation
Follow its instructions without thinking about the next step
Download address:
Docs.docker.com/desktop/win…
After the installation is complete, it will have a novice boot, just follow the above command to run, about 4 steps after completion, Docker has been installed.
You can view the docker information by viewing the version number
docker -v
You can then use docker commands in power shell to manipulate docker
Such as:
configuration
In the source
Use a domestic source instead of the default docker source
"https://hub-mirror.c.163.com",
"https://ustc-edu-cn.mirror.aliyuncs.com",
"https://ghcr.io",
"https://mirror.baidubce.com"
Copy the code
test
Pull the Nginx image
docker pull nginx:latest
Copy the code
Port mapping + Create and start Nginx
docker run --name my-nginx -p 80:80 -d nginx
Copy the code
–name my-nginx Specifies the container name
-p 80:80 Indicates the mapping port
-d The daemon process is running
Nginx image version, you can also specify the version, such as: nginx:1.18.0
If you simply want to start a test nginx, the test results are as follows
Stop + delete nginx
Stop means stop, and the trash can icon on the right means delete
Command line delete:
Docker Network Connection (real pit)
The connection container bug is mostly due to this pit
Docker for Win10 Docker is actually running on a newly built WSL2 host. How do YOU communicate with Windows at this point?
There are three IP addresses:
- IP address of the Docker container
- Linux host IP
- Local Windows IP
Which IP address can I access the application inside the container?
Use the common test container Nginx
Test results:
You can see that using localhost, you can access it. This is an optimization of WSL2
At the same time, many images do not even have Net-Tools installed and cannot view IP directly. By default, the container hides the IP from the outside
If the container hides the IP from the outside by default, then the way to connect to the container is completely through the DOCker host IP+ port forwarding (access the designated port on the host, and then the host port helps jump to the container port).
Docker for Windows Desktop edition is a special way to install Docker for Windows. Docker host IP is set to be the same as the local Windows IP. In the WSL2 direct installation mode, the two are different IP addresses, but under the same WSL subnet.
Ping the IP address and port number of the container
Docker for Windows has been using the container port +3306 to connect to the database. Or Windows Firewall policy.
Heretical Forwarding test (install docker, run this test) :
View disabled ports
netsh interface ipv4 show excludedportrange protocol=tcp
Copy the code
Select 9999 as the test port number to test:
View port forwarding:
Docker MySQL installation + configuration + connection
Configuring the run container
To view forbidden ports:
netsh interface ipv4 show excludedportrange protocol=tcp
Copy the code
Select 6666 as the local port number
To start the MySQL container, specify the initial password and port mapping
The password is set to root
Docker run --name MYSQL -e MYSQL_ROOT_PASSWORD=root -p 6666:3306 -itd MYSQL :5.7 /bin/bashCopy the code
Connect to container
Log in to MySQL in the container
MySQL > alter character set;
Go into the container and modify the my.cnf file
Look for the my.cnf file
mysql --help | grep my.cnf
Copy the code
Modify the /etc/mysql.my.cnf file
Pitfall: No Nano or VI
Without vi and nano, how to change file + change source?
Use manual Echo to add the source and then install the Nano
-
Backup source
cp /etc/apt/sources.list /etc/apt/sources.list.bak Copy the code
-
Delete the original sources.list
rm -rf /etc/apt/sources.list Copy the code
-
Manually echo to add a source
Echo source > sources. The list
echo deb http://mirrors.aliyun.com/debian/ buster main non-free contrib deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib deb http://mirrors.aliyun.com/debian-security buster/updates main deb-src http://mirrors.aliyun.com/debian-security buster/updates main deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib > sources.listCopy the code
-
update
apt update apt upgrade Copy the code
-
Install the nano
apt install nano Copy the code
Began to change
nano /etc/mysql/my.cnf
Copy the code
The character set parameter to add
[mysqld]
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
Copy the code
Enter mysql to query the character set
show variables like '%character%';
Copy the code
Restart the MySQL container to query the character set
Configure MySQL to allow remote login
Choose mysql database
use mysql;
Copy the code
View user table
SELECT `Host`,`User` FROM user;
Copy the code
If it is not %, use the modify command
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
Copy the code
Local Windows connects to the MySQL container
Set IP to localhost and port number to the local forwarding port selected when creating a container
The connection is successful
reference
Blog. Lupf. Cn/articles / 20…
Blog.csdn.net/weixin_4585…
zhuanlan.zhihu.com/p/365632905
www.cnblogs.com/sablier/p/1…
zhuanlan.zhihu.com/p/372062996
zhuanlan.zhihu.com/p/266534015
zhuanlan.zhihu.com/p/143857664