Summary of Docker common commands and precautions for use _docker

Source: Internet
Author: User
Tags file copy redmine docker ps docker cp docker run

Common Docker commands

The detailed explanation of Docker commonly used name, let you quickly learn Docker use!

Docker, lightweight virtual machines, also known as application containers

Advantages: 1, fast deployment 2, testing services and deployment can be maintained in full agreement

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 at the start of the Docker container is randomly assigned. So, in this way, you can get the password of the root user of the Redmine container.

2. View Container Log

Docker Logs-f < container name orid>

3. View the container that is running

Docker PS
Docker ps-a for viewing all containers, including those that have been stopped.

4. Remove all containers

Docker RM $ (Docker ps-a-Q)

Delete a single container

Docker RM < container name Orid>

5. Stop, start, 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. Remove all Mirrors

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

8. Run a new container, naming it, port mappings, and folder mappings. Take Redmine image as an example

Docker run--name redmine-p 9003:80-p 9023:22-d-v/var/redmine/files:/redmine/files-v/var/redmine/mysql:/var/lib/mys QL Sameersbn/redmine

9. One container 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 the Mmysql container is renamed to DB. In this way, the sonar container can use the related environment variables of DB.

Pull Mirror

Docker Pull < mirror name:tag>

Such as

Docker Pull Sameersbn/redmine:latest

11. When you need to migrate a mirror on a machine to another machine, you need to save the mirror and load the mirror.

Machine A

Docker Save Busybox-1 >/home/save.tar

Use the SCP to handcuff Save.tar to machine B, and then:

Docker Load  
 

12. Build Your own mirrors

Docker build-t < mirror name > <dockerfile path >

such as Dockerfile in the current path:

Docker build-t Xx/gitlab.

13. Re-view the container stdout

# Start top command, background run
$ id=$ (sudo docker run-d ubuntu/usr/bin/top-b)
# get running output
$ sudo container docker Ch $ID
top-02:05:52 up 3:05, 0 users, load average:0.01, 0.02, 0.05
Tasks:  1 Total,  1 running,  0 SL Eeping,  0 stopped,  0 zombie
Cpu (s): 0.1%us, 0.2%sy
, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem:  373572k Total,  355560k used,  18012k free,  27872k buffers
Swap:  786428k Total,    0k used,  786428k free,  221740k cached
^c$
$ sudo docker stop $ID

14. Background run (-D), and exposed ports (-p)

Docker run-d-P 127.0.0.1:33301:22 centos6-ssh

15. copy files from container

sudo docker CP 7bb0e258aefe:/etc/debian_version.

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

Note: as long as 7bb0e258aefe has not been deleted, the file namespace is still in, you can rest assured that the exit state of the container file copy out

Note implementation:

1.ubuntu14 under the Docker is no service. To remove every sudo run docker command, you need to add a group:

# ADD The Docker group if it doesn ' t already exist.
$ sudo groupadd docker
#改完后需要重新登陆用户
$ sudo gpasswd-a ${user} docker

2.UBUNTU14 's febootstrap does not have the-I command

The difference between the expose, Docker run--expose, and Docker run-p in 3.Dockerfile

The Dockerfile expose corresponds to the Docker run--expose, which provides port access between container. Docker run-p allows container external host to access container ports

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.