Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common docker commands?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what the commonly used docker commands are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Common command

View the root user password of the container

Docker logs 2 > & 1 | grep'^ User:'| tail-N1

Because the password of the root user when the Docker container starts is randomly assigned. So, in this way, you can get the password of the root user of the redmine container.

View container log

Docker logs-f

View running containers

Docker psdocker ps-an is to view all containers, including those that have been stopped.

Delete all containers

Docker rm $(docker ps-a-Q)

Delete a single container

Docker rm

Stop, start, kill a container

Docker stop docker start docker kill

View all mirrors

Docker images

Delete all mirrors

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

Run a new container and name it, port mapping, and folder mapping. Take redmine image as an example

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

One container is connected to another

Docker run-I-t-- name sonar- d-link mmysql:db tpires/sonar-serversonar

The container connects to the mmysql container and renames the mmysql container to db. In this way, the sonar container can use the relevant environment variables of db.

Pull the image

Docker pull

Such as

Docker pull sameersbn/redmine:latest

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 save busybox-1 > / home/save.tar

Use scp to copy save.tar to machine b, and then:

Docker load < / home/save.tar

Build your own image

Docker build-t

For example, Dockerfile is in the current path:

Docker build-t xx/gitlab.

Re-view the stdout of container

# start the top command Run $ID=$ (sudo docker run-d ubuntu / usr/bin/top-b) # in the background to get the output of container in running $sudo docker attach $IDtop-02:05:52 up 3:05, 0 users, load average: 0.01,0.02, 0.05Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombieCpu (s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa 0.0%hi, 0.0%si, 0.0%stMem: 373572k total, 355560k used, 18012k free, 27872k buffersSwap: 786428k total, 0k used, 786428k free, 221740k cached ^ C $$sudo docker stop $ID

Run in the background (- d) and expose the port (- p)

Docker run-d-p 127.0.0.1 purl 33301purl 22 centos6-ssh

Copy files from Container

Sudo docker cp 7bb0e258aefe:/etc/debian_version.

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

Note: as long as the 7bb0e258aefe is not deleted, the file namespace is still there. You can safely copy the container file in the exit status.

Pit

There is no service service for docker under ubuntu14. Every time sudo runs the docker command, you need to add a group:

# you need to log in to user $sudo gpasswd-a ${USER} docker after Add the docker group if it doesn't already exist.$ sudo groupadd docker# modification

Ubuntu14's febootstrap does not have the-I command

The difference between EXPOSE, docker run-- expose and docker run-p in Dockerfile

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

The above is all the contents of the article "what are the commonly used docker commands?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report