1. Docker service management
1.1. Installation
yum install docker
1.2. Start
service docker start
chkconfig docker on
systemctl start docker.service
systemctl enable docker.service
1.3. Stop
systemctl stop docker.service
1.4. Reboot
systemctl restart docker
1.5. Set proxy for docker service
1)mkdir /etc/systemd/system/docker.service.d
2)touch /etc/systemd/system/docker.service.d/http-proxy.conf
The content is as follows:
[Service] Environment="HTTP_PROXY=10.125.156.21:8118HTTPS_PROXY=10.125.156.21:8118"
3 ) Refresh configuration:
systemctl daemon-reload
1.6 Configure the official domestic acceleration image for docker
My docker version is 1.12.6 . For version 1.12 , you can modify the file:
vi/etc/docker/daemon.json
"registry-mirrors":["https://registry.docker-cn.com"]
2. Mirror operation
2.1 Search mirrors:
docker search image_name
2.2 Download mirror:
docker pull image_name
2.3 View the local mirror:
docker images
2.4 Delete local mirror
docker rmi image_name
2.5 Create an image based on a running container
docker commit container_id new_image_name
2.6 Make an image based on the current operating system iso
to be continued
2.7 Export image
docker export container_id >export_image_name
2.8 Import image
cat export_image_name|docker import - ${your_repo_name}:${your_tag_name}
3 Container operation
3.1 Based on the local image, run the command in the new container
docker run image_name
Common parameters
docker run -itd --privileged=true -phost_ip:host_port:container_host_port --net=host
-v/path/to/host/directory:/path/to/container/directory image_name command
3.2列出本地容器
docker ps
列出所有容器
docker ps -a
3.2进入运行的容器中
docker attah container_id
3.3多终端登录容器
docker exec -it container_id bash
3.4查看容器日志
docker logs container_id
3.5删除容器
docker rm container_id
3.6退出并中止容器运行
容器内输入exit或ctrl+d
3.7退出不中止容器运行
ctrl+p+q
3.8启动已停止运行的容器
docker start container_id
4.容器和宿主机之间传文件
4.1.从容器copy到宿主机:
docker cp container_id:/from/container/path/filename /to/host/path/filename
4.2从宿主机copy到容器
挂载宿主机本地目录到容器里。
docker run -v /path/to/host/directory:/path/to/container/directoryimage_name command