Simple usage of docker

Simple usage of docker

Simple principle:
conventional virtualization: host machine -- "virtual machine software -- "virtual system -- "install software
docker: host machine -- "docker software -- "install software image

1. Install docker
1. Need kernel 3.8 or above
2. Centos6.5 or above
3. yum install docker*

2. Start
systemctl restart docker.service

3. Check the output of the local image
docker imagers with only the title, indicating that there is no local image

Fourth, search for public images
docker search nginx

5. Download the image
docker pull docker.io/nginx
docker.io/nginx is the first one in the fourth search result, and the name column in it

如果已经将镜像文件下载到本地,可以使用命令导入
cat 镜像文件名 | docker import - 虚拟机名字(自主命名)

6. After the download is successful, check the local image
docker imagers again

7. Run the image
docker run -itd docker.io/nginx
docker.io/nginx: The repository value of the output result in the sixth item
i: interaction; t: terminal; d: background start

8. View the started image (container or virtual machine) In the status field in the output of
docker ps -a , if it is up, it means startup

9. Execute the command in the
virtual machine docker exec ID number of the virtual machine The command of the
virtual machine The ID number of the virtual machine is the first column of the eighth output result

10. Enter the virtual machine
docker exec -it The ID number of the virtual machine /bin/bash
/bin/bash is an example
output result: the command line interface of the virtual machine

Eleven, port mapping
docker run -itd -p 80:80 docker.io/nginx maps
the local port 80 to the 80 port of docker.io/nginx; the previous 80 represents the local port 80

12. Delete the virtual machine (container)
docker rm -f The ID number
of the virtual machine can be connected to multiple "ID numbers of the virtual machine", separated by spaces

13. Start a service of the virtual machine in the host
docker exec -it the ID number of the virtual machine command full path start

14. Export the image
docker export the ID number of the virtual machine>image name.tar

15. Terminate the virtual machine process
docker kill the ID number of the virtual machine

16. View the virtual machine status
docker status ID number of the virtual machine

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324518096&siteId=291194637