Summary of practical tips for daily use of docker (Recommended)
- 2020-06-23 02:22:52
- OfStack
preface
Docker is an open source engine that automatically deploys development applications to containers. It was written by the Docker team and licensed under the Apache 2.0 open source protocol. It provides a simple, lightweight modeling approach that makes the development lifecycle more efficient and fast, encouraging service-oriented architecture design. The Docker project aims to achieve a lightweight operating system virtualization solution. Docker is based on technologies such as the Linux container (LXC). On the basis of LXC, Docker has carried out a step further encapsulation, so that users do not need to care about the management of the container, making the operation easier. Users manipulating the Docker container is as simple as operating a fast, lightweight virtual machine.
Docker 1 May seem daunting at first, but it's a great tool.
For better use of docker, it is recommended to upgrade to 1.13. Note that the following commands are based on 1.13!
# Upgrade instruction ( centos7 Tested)
yum-config-manager --add-repo https://docs.docker.com/v1.13/engine/installation/linux/repo_files/centos/docker.repo
yum makecache fast
yum -y remove docker docker-common container-selinux
yum -y install docker-engine-1.13.1
Clear the disk space occupied by docker
# Clean up no dependent images and containers that are not running, containers that are not in use with the network (force clean up with -f )
docker system prune
# Clean up images that have no dependencies -f )
docker image prune
# Clear containers that are not running (force cleanup is used -f )
docker container prune
# Clear a network that is not in use -f )
docker network prune
# Clear container volumes that are not in use -f )
docker volume prune
View docker taking up docker space
docker system df
Create a bootup container
docker run --restart=always my_image
Create an exit self - delete container
docker run --rm my_image
Container health check
# Specify ( timeout Execute command timeout, health-interval Time interval between execution of inspection)
docker run -d --health-cmd "curl -f http://localhost/123 || exit 1" --health-interval=5s --timeout=3s my_image
# Dockerfile Specify ( timeout Execute command timeout, interval Time interval between execution of inspection)
HEALTHCHECK --interval=60s --timeout=10s CMD curl -f http://127.0.0.1/ || exit 1
docker swarm cluster related commands
# Create the cluster
docker swarm init --advertise-addr { The machine address }
# Get the join cluster command (administrator node)
docker swarm join-token manager
# Get the join cluster command (normal node)
docker swarm join-token worker
# Display node list
docker node ls
# Display existing services
docker service ls
# Displays the container under a service
docker service ps { The service name }
# create 1 A service
docker service create --replicas { Number of instances } --name { The service name } -p { The host port }:{ Container interior port } my_image { Start the instruction }
# delete 1 A service
docker service rm { The service name }
# Modify the number of instances
docker service scale { The service name }={ The service number }
# Modify the instance to use an image
docker service update --image { Image name } { The service name }
# Change the instance memory limit
docker service update --limit-memory { Memory usage } { The service name }
# Modify the instance cpu limit
docker service update --limit-cpu { Memory usage } { The service name }
View the container occupancy resource situation
docker stats
View all images
docker images
Check the container
# View the running container
docker ps
# Look at all the containers
docker ps -a
conclusion