What is a docker??
To be honest, it is not easy to say what a Docker is. I will explain to you what a Docker is through four points below. Docker is the world’s leading software container platform. Docker uses the Go language launched by Google for development and implementation. Based on cgroup, Namespace, AUFS class UnionFS and other technologies, Docker encapsulates and isolates processes, which is a virtualization technology at the operating system level. Since a quarantined process is independent of the host and other quarantined processes, it is also called a container. Docke was originally implemented based on LXC. Docker automates repetitive tasks, such as setting up and configuring development environments, freeing up developers to focus on what really matters: building great software. Users can easily create and use containers and put their own applications into containers. Containers can also be versioned, copied, shared, and modified just like normal code. Original text: dockone. IO/article / 605…
Docker installation:
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce-18.06.1.ce-3.el7
$ systemctl enable docker && systemctl start docker
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
Copy the code
Because docker image of the foreign very slow recommendation page Ali Docker image library:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://rsj0shyq.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code
Basic operations of Docker
1. Start and stop Docker
The systemctl command is a system service manager command. It is a combination of service and chkconfig commands. Start docker: systemctl start docker Stop docker: systemctl stop docker Restart docker: systemctl restart docker Check the docker status. Systemctl status Docker: systemctl enable docker
2. List the mirror
List all images under Docker: Docker images
TAG: IMAGE ID: IMAGE ID CREATED: CREATED date of the IMAGE (not the date of obtaining the IMAGE) SIZE: IMAGE SIZE These images are stored in the /var/lib/docker directory of the Docker host
3. Create a container
Create container command: docker run
-i: runs the container. -t: displays the command line after the container is started. After adding these two parameters, the container creation can be logged in. That is, assign a dummy terminal. --name: Name the created container. -v: indicates directory mapping (the former is a host directory, and the latter is a directory mapped to the host). You can use multiple -v to map multiple directories or files. Note: It is best to do directory mapping, make changes on the host, and then share them on the container. -d: If run is followed by -d, a daemon container will be created and run in the background (this will not automatically log in to the container after creating the container. If you only add -i -t, it will automatically log in to the container). -p: indicates port mapping. The former is a host port, and the latter is a mapped port in the container. --restart no/on-failure:10/unless-stopped/always specifies the restart policy.Copy the code
Restart Parameter description
No The container is not restarted automatically (default value) on-failure The container exits with an error (the container exit status is not 0) restart the container. You can specify the maximum number of times the container restarts, for example: On-failure :10 unless-stopped Restarting containers when the containers have been stopped or a Docker stoped/ lua/task_flow is always restarted when the containers have been stopped or a Docker has been stopped Restarted containers are restarted only when stoped/restarted manually
Note: If the container has already been created, we want to modify the container restart policy
Docker update --restart no Container IDCopy the code
Other parameters about docker run can be viewed with docker run –help
4. Stop and start the container
Stop a running container: docker stop container ID
Start running containers: docker start Container ID
Run the following command to restart running containers: docker restart Container ID
Docker common parameters:
1. Search for docker images
Docker Search Specifies the image nameCopy the code
2. Download the Docker image
Docker pull name: versionCopy the code
3. View the running Docker container
Docker ps -a Optional: View all docker containersCopy the code
4. Delete the container
Docker rm container ID // Delete a single container docker rm 'docker ps a-q' // Delete all containersCopy the code
5. Delete the mirror
Docker RMI image IDCopy the code
6. Enter the container
Docker exec -it Container ID /bin/bashCopy the code
7. View detailed information about the container
Docker inspect Container IDCopy the code
Docker’s own IP
Docker inspect - format '{{. NetworkSettings. IPAddress}}' container idCopy the code
9. Copy docker files
Docker cp File or directory to copy Container name: container directoryCopy the code