This is the seventh day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Docker is an open source project that was born in early 2013 as a side project within dotCloud. It is based on the Go language implemented by Google. The project has since joined the Linux Foundation, is Apache 2.0 compliant, and the project code is maintained on GitHub.

The goal of Docker project is to achieve a lightweight operating system virtualization solution. With Docker, development and testing can rapidly deploy and migrate the environment, and ensure the consistency of the environment, so as to improve the efficiency of software development and maintenance.

Compared with virtual machines, Docker has advantages and disadvantages, as shown in the following figure:

Just recently in the deployment environment, the docker commonly used operations and commands to give you a summary:

Docker process commands

  • systemctl start dockerStart docker service
  • systemctl stop dockerStop docker service
  • systemctl restart dockerRestart the Docker service
  • systemctl status dockerCheck docker service status
  • systemctl enable docker# Set the boot service

Docker container management commands

Docker run –name={your_name} –d {image_name

Parameter description:

-i: keeps the container running. It is usually used together with -t. After the it parameter is added, the container is automatically entered after creation, and the container is automatically closed after exit.

-t: Reallocates a pseudo input terminal to the container, usually used in conjunction with -i.

-d: Runs the container in daemon (background) mode. Creating a container to run in the background requires using Docker Exec to enter the container. After exit, the container does not close.

– The containers created by it are generally called interactive containers, and the containers created by -id are generally called daemon containers

–name: specifies the name of the created container.

  • docker ps# View the running container
  • docker ps -s -a# View all current containers
  • Docker stop Container name# Stop container
  • Docker restart Container name# Restart container
  • Docker kill Container name# Kill the container
  • Docker rm -f Image ID or image nameDelete the stopped container

If the container is running, the deletion fails. You need to stop the container to delete it

Docker Image management commands

  • docker imagesView all images of the current machine
  • Docker images - q# View the id of the image used
  • Docker Search Image name# Search for images. Find the desired images in the network
  • Docker pull Image name# Pull image from Docker repository, name: version number
  • Docker push image name# Push image
  • Docker RMI image name/IMAGE IDDelete the image from the local machine
  • docker rmi docker images -qDelete all local mirrors
  • Docker tag Image name :tag Image name :tag# Tag an image
  • docker save {image_name} > {new_image_name}.tarThe image is packaged as a tar package
  • docker load < {image_name}.tar# Decompress an image tar package

Docker View log information

  • docker logs -fContainer name # View the container log
  • docker infoCheck docker service information
  • Docker INSPECT Container name# Obtain the meta information of the mirror

Commands to interact with the container

Enter the running container

Docker exec -it container ID or container name /bin/bashCopy the code

Exec means to run a command in the container. /bin/bash is written naturally because docker must run a process in the background or the container will exit. In this case, it means to start bash after starting the container.

Out of the container

Also close the container;

Ctrl+P+Q # to exit without closing the container

When creating a startup container, use the -v parameter to set the data volume

docker run ... -v Host directory/files: directory/files in the containerCopy the code

A data volume is a directory or file on the host

Directory must be an absolute path

If the directory does not exist, it is automatically created

Multiple data volumes can be mounted

Copy files

Docker cp Host file path Container ID or container name: Container path # Host file is copied to the container

Docker cp Container ID or container name: container path Host file path # The container file is copied to the host

Sorting is not easy, feel useful, remember to click a like