1. Preparation (close the firewall, or not close)
1.1 Turn off and disable the firewall
systemctl stop firewalld && systemctl disable firewalld
1.2
setenforce 0
2. Install and configure the Docker repository:
2.1 install docker yum install -y yum-utils 2.2 Configure docker warehouse yum-config-manager --add-repo https://sandbox-expriment-files.obs.cn-north-1.myhuaweicloud.com:443/study-container/docker-ce.repo 2.3 Install Docker container service: yum install -y docker-ce docker-ce-cli containerd.io 2.4 Start the docker service: systemctl start docker 2.5 Set the docker service to start automatically at boot systemctl enable docker
3. Modify the docker image accelerator:
3.1 Get mirror accelerator address In the left menu bar of the browser page of the HUAWEI CLOUD console, click "Service List" -> "Container" -> "Container Image Service SWR", In the navigation pane on the left, choose Image Resource > Image Center, click + Image Accelerator, and obtain the address of the image accelerator in the displayed dialog box. 3.2 Modify the configuration file /etc/docker/daemon.json Modify the "/etc/docker/daemon.json" file in the virtual machine (if not, you can create it manually) [root@localhost ~]# vi /etc/docker/daemon.json Add the following content in the file: (replace xxxxx with the accelerator address obtained in the previous step) { "registry-mirrors": ["xxxxx"] } Then press Ecs, :wq to save and exit.
4. Restart docker
4.1 Restart docker [root@localhost ~] # systemctl restart docker 4.2 View docker running status [root@localhost ~] # systemctl status docker
5. Run an httpd container
5.1 Start the docker container, (start httpd on port 80) [root@localhost ~]# docker run -d -p 80:80 httpd [root@localhost ~]# docker run -d --name sjc_httpd -p 99:80 httpd The docker container name is sjc_httpd, the server port is 99, the docker container port is 80, and the image uses the httpd image 5.2 Verify whether the startup is successful Enter http://elastic cloud host elastic public network IP address:80 in the browser.
6. Container related commands (operations)
6.1 Check the running container information: (container information will be displayed, including the running container ID, container means the container ) [root@localhost ~] # docker container ls or [root@localhost ~]# docker ps 6.2 View container image information: (display image ID) [root@localhost ~]# docker image ls 6.3 Stop the container [root@localhost ~] # docker stop container ID 6.4 Start the container [root@localhost ~] # docker start container ID 6.5 Delete the container (you need to stop the container first) [root@localhost ~] # docker rm container ID 6.6 Access to container [root@localhost ~] # docker exec -it container ID bash 6.7 Exit the container [root@container ID ~] # exit