1. Centos deploys Docker container virtualization platform
Installing Docker environment dependencies
yum install -y yum-utils device-mapper-persistent-data lvm2
Configure yum source of domestic Docker (Alibaba cloud)##
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Docker installation
yum install docker-ce docker-ce-cli containerd.io -y
Docker CE cli is a docker command line tool. containerd.io is a container interface related package.
Start the Docker service and start it
systemctl start docker && systemctl enable docker
2. Pull image - configure image acceleration address
First, you can use the * * docker search imageName command to find the required image. Then use docker pull imageName * * to pull the image. If the version number is not added, pull latest.
However, this method is slow to pull images. Several methods are recommended below.
(1) Change the image download address
It is recommended to use Alibaba cloud Docker image accelerator to improve the pull speed. You can also choose other accelerators, such as Netease, with the same principle.
Netease image addresses are also provided here: https://c.163.com/hub#/m/home/
Log in to Alibaba cloud image accelerator console, https://cr.console.aliyun.com . The image tool - image accelerator in the menu bar on the left side of the console page will display the assigned acceleration address in the format of https://xxxxxxxx.mirror.aliyuncs.com .
Edit the daemon.xml using vim JSON file (this file does not exist by default, and VIM will create it automatically).
vim /etc/docker/daemon.json
daemon.json file content is added as follows. Multiple image acceleration addresses can be configured ["address 1", "address 2", "address 3]:
{ "registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"] }
Then execute the following two commands in sequence:
systemctl daemon-reload systemctl restart docker
Finally, use the docker info command to check whether the address of Registry Mirrors is an acceleration address. Then pull the image, which will be very fast.
(2) Pull the image offline
This method uses the operations related to Docker image import and export.
First of all, you need to download the image file (suffix. tar) through other channels in advance, upload it to the Linux server through ftp, and then import the image with the following command.
docker load -i xxx.tar
Similarly, you can also use the following command to export an image in the images repository. Of which, XXX Tar is the name of the exported tar file. imageName:latest selects the image of the specified TAG
docker load -o xxx.tar imageName:latest
3. Enable Docker routing forwarding function
It is on by default. This configuration is not required.
However, if the console reports the following error when you start the Docker instance, you need to configure it.
WARNING: IPv4 forwarding is disabled. Networking will not work.
First use VIM / etc / sysctl Conf command, add content net ipv4. ip_ forward = 1.
# sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward = 1
Then use sysctl -p to make the configuration effective. You can also use cat /proc/sys/net/ipv4/ip_forward to check whether the routing forwarding function is enabled. The following is the console history.
[root@atlantis ~]# vim /etc/sysctl.conf [root@atlantis ~]# sysctl -p net.ipv4.ip_forward = 1 [root@atlantis ~]# cat /proc/sys/net/ipv4/ip_forward 1 [root@atlantis ~]#
Then close the firewall, restart the Docker service, and use iptables -L -n to find many more Docker related firewall rules.
[root@atlantis ~]# systemctl stop firewalld && systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@atlantis ~]# systemctl restart docker [root@atlantis ~]# iptables -L -n ······
4. Basic use of docker
There are too many commands. Please use Baidu for specific methods.
Docker command tab automatic completion
If some Docker commands cannot be completed automatically by using tab, execute the following three commands in sequence.
yum install -y bash-completion source /usr/share/bash-completion/completions/docker source /usr/share/bash-completion/bash_completion