Preface
Docker is an open source engine that can automatically deploy development applications to containers. It is written by a team from Docker and is licensed based on the Apache 2.0 open source protocol. It provides a simple, lightweight modeling method that makes the development life cycle more efficient and fast, and encourages service-oriented architecture design. The goal of the Docker project is to implement a lightweight operating system virtualization solution. Docker is based on technologies such as Linux containers (LXC). Based on LXC, Docker has further encapsulated so that users do not need to care about container management, making operation easier. Users operate Docker's containers as simple as operating a fast and lightweight virtual machine.
Docker may be daunting at first, but it is indeed a very great tool.
In order to better use docker, it is recommended to upgrade to 1.13. Note that the following commands are all based on 1.13!
# Upgrade command (tested in centos7)yum-config-manager --add-repo /v1.13/engine/installation/linux/repo_files/centos/ 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
# Clear the image without dependencies and the container that stops running, and the container volume and network that are not used (force clearance is used -f)docker system prune # Clear images without dependencies (force clearance with -f)docker image prune # Clear the container that is stopped (for forced clearing -f)docker container prune # Clear unused networks (force clearance for -f)docker network prune # Clear unused container volumes (for forced cleaning -f)docker volume prune
Check the docker occupies docker space
docker system df
Create a self-start container
docker run --restart=always my_image
Create an exit self-delete container
docker run --rm my_image
Container health check
# Specify the timeout execution command timeout when starting the container (timeout execution command timeout, health-interval execution check interval time)docker run -d --health-cmd "curl -f http://localhost/123 || exit 1" --health-interval=5s --timeout=3s my_image # Dockerfile specifies (timeout execution command timeout, interval execution check interval)HEALTHCHECK --interval=60s --timeout=10s CMD curl -f http://127.0.0.1/ || exit 1
Docker swarm cluster related commands
# Create a clusterdocker swarm init --advertise-addr {Local address} # Get the join command (administrator node)docker swarm join-token manager # Get the joining command (normal node)docker swarm join-token worker # Show node listdocker node ls # Show existing servicesdocker service ls # Show containers under a servicedocker service ps {Service name} # Create a servicedocker service create --replicas {Number of instances} --name {Service name} -p {Host Port}:{Container internal port} my_image {Start command} # Delete a servicedocker service rm {Service name} # Modify the number of instancesdocker service scale {Service name}={Number of services} # Modify instances to use mirrorsdocker service update --image {Mirror name} {Service name} # Modify instance memory limitdocker service update --limit-memory {Memory usage} {Service name} # Modify instance CPU restrictionsdocker service update --limit-cpu {Memory usage} {Service name}
Check the container's resource occupancy
docker stats
View all images
docker images
View container
# View running containersdocker ps # View all containersdocker ps -a
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.