Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

What happens to Docker Run

How does Docker work

Docker is a C/S (client-server) structure of the system, Docker daemon running on the local machine, through sockets from the Client access

DockerServer executes this command when it receives the docker-client instruction

Docker has fewer layers of abstraction than virtual machines

* Docker common commands

The help command

Docker version docker info docker command --help # universal commandCopy the code

* Basic commands for mirroring

docker images

Docker images <-a -f -q> # REPOSITORY TAG ID CREATED SIZE # REPOSITORY TAG ID CREATED SIZE Options: -a, --all Show all images (default hides intermediate images) --digests Show digests -f, --filter filter Filter output based on conditions provided --format string Pretty-print images using a Go template --no-trunc Don't TRUNCate output -q, --quiet Only show image IDs Displays Only IDsCopy the code

Docker Search searches for images

docker search mysql --filter=STARS=3000
Copy the code

Docker pull Downloads the image

Docker pull mysql docker pull mysql:tag # Check the image tagCopy the code

Docker RMI delete image

Docker images -aq: < ImageId >Copy the code

* Basic commands for containers

Note: You can create containers only with images

Create a new container and start

docker run --help
Copy the code
Docker run [optional] <image> # docker run [optional] <image> -p # Specify the port of the container -p 8080:8080 -p Host port: container port -p Container port (not going out) Container port -p IP: host port: container port -p # Randomly specify the portCopy the code
Docker run -it centos /bin/bash exitCopy the code

View running containers

Docker ps -a =1 docker ps -aq # lists the id of the container. Docker ps -a =1 docker ps -aq # lists the ID of the containerCopy the code

Remove the container

Docker rm containers < id > docker rm $(docker ps - aq) docker rm -f # mandatory delete docker ps - a - q | xargs docker rm # to delete all of the containerCopy the code

Start and stop container operations

Docker start < id> docker restart < id> docker stop < ID > docker kill < ID > # Force stop docker pause < ID > # stop docker Unpause < container ID > # Start containerCopy the code

* Other commonly used commands

View docker container logs

# docker logs --help docker logs -f -t --tailCopy the code
docker run -d centos /bin/sh -C "while true; do echo tongtong; sleep 1; Docker logs -f -t --tail < id>Copy the code

View the process information in the container

Docker top --help docker top < docker id>Copy the code

View the metadata of the mirror

docker inspect --help
​
Copy the code

Enter the currently running container

# We usually run containers in the background, Docker attach < container ID > # docker attach < container ID > # Enter the running container and print logs if there are any. To exit the container, press CTRL + P + Q. Otherwise, the container will stopCopy the code

Copy files from a container to a host

Docker cp < docker id > Docker run -itd centos docker ps For example :a123456 docker exec a123456 /bin/bash # or Docker attach a123456 to the container CD root & touch test.js # Create test file exit # or CTRL + p + q exit vessel docker cp a123456: / root/test. The js/Users/xujiantong/Desktop # # file copy container to host copy is a manual process, in the future we use - v volume of technology, Automatic synchronization can be achievedCopy the code