Summary of common Docker commands

  • 2020-05-30 21:22:23
  • OfStack

The docker command is commonly used

A detailed explanation of the common names of docker, so that you can quickly learn the use of docker!

docker, a lightweight virtual machine, is also known as the application container

Advantages: 1, the deployment speed is fast 2, the test service and deployment can be maintained completely 1

Common commands

1. View the root user password for the container


docker logs < Container name orID> 2>&1 | grep '^User: ' | tail -n1

Because the password for the root user when the Docker container is started is randomly assigned. Thus, the password of the root user of the redmine container can be obtained in this way.

2. View the container log


docker logs -f < Container name orID>

3. View the running container


docker ps
docker ps -a For viewing all containers, including those that have been stopped. 

4. Delete all containers


docker rm $(docker ps -a -q)

Delete a single container


docker rm < Container name orID>

5. Stop, start, and kill a container


docker stop < Container name orID>
docker start < Container name orID>
docker kill < Container name orID>

6. View all mirrors


docker images

7. Delete all images


docker rmi $(docker images | grep none | awk '{print $3}' | sort -r)

8. Run a new container, naming, port mapping, and folder mapping it at the same time. Take the example of redmine mirroring


docker run --name redmine -p 9003:80 -p 9023:22 -d -v /var/redmine/files:/redmine/files -v /var/redmine/mysql:/var/lib/mysql sameersbn/redmine

9.1 containers are connected to another container


docker run -i -t --name sonar -d -link mmysql:db  tpires/sonar-server
sonar

10. The container is connected to the mmysql container and renamed the mmysql container to db. In this way, the sonar container can use the environment variables associated with db.

Pull the mirror


docker logs -f < Container name orID>
0

Such as


docker logs -f < Container name orID>
1

11. When you need to migrate an image from one machine to another, you need to save the image and load the image.

Machine a


docker logs -f < Container name orID>
2

Copy save.tar to machine b using scp, then:


docker load < /home/save.tar

12. Create your own mirror image


docker logs -f < Container name orID>
4

As Dockerfile in the current path:


docker logs -f < Container name orID>
5

13. Recheck stdout for container


docker logs -f < Container name orID>
6

14. Running in the background (-d), and exposing the port (-p)


docker logs -f < Container name orID>
7

15. Copy the file from Container


sudo docker cp 7bb0e258aefe:/etc/debian_version .

Copy of 7 bb0e258aefe etc/debian_version to the current directory.

Note: as long as 7 bb0e258aefe not deleted, the file name space is still in, can rest assured of the exit container file copy out of state

Note implementation:

1. docker under ubuntu14 has no service service. Remove every time sudo runs the docker command, you need to add a group:


docker logs -f < Container name orID>
9

2. febootstrap of ubuntu14 does not have the -i command

3. Differences between EXPOSE, docker run --expose, docker run-p

EXPOSE of Dockerfile is equivalent to docker run --expose, providing port access between container and container. docker run-p allows external hosts of container to access the port of container

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: