Common Docker commands, and some pits

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

Common Docker commands, and some pits
Common Commands

View the root user password for the container

Docker logs < container name Orid> 2>&1 | grep ' ^user: ' | Tail-n1

Because the root user's password is randomly assigned when the Docker container starts. Therefore, the password of the root user of the Redmine container can be obtained in this way.

View Container Logs

Docker Logs-f < container name orid>

To view a running container

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

Remove all containers

Docker RM $ (Docker ps-a-Q)

Delete a single container

Docker RM < container name Orid>

Stop, start, kill a container

Docker Stop < container name Orid>
Docker start < container name orid>
Docker kill < container name orid>

View all Mirrors

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

Run a new container, naming it, port mapping, and folder mapping. Take Redmine Mirror 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

One container connected to another container

Docker run-i-T--name sonar-d-link mmysql:db   tpires/sonar-server
sonar

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 relevant environment variables of DB.

Pull Mirror

Docker Pull < mirror name:tag>

Such as

Docker Pull Sameersbn/redmine:latest

When you need to migrate a mirror on one machine to another machine, you need to save the image and load the image.
Machine A

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

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

Docker Load 

Build Your own image

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

such as Dockerfile in the current path:

Docker build-t Xx/gitlab.
Re-view Container's stdout
# Start top command, background run
$ id=$ (sudo docker run-d ubuntu/usr/bin/top-b)
# Get output of container being running
$ sudo docker atta Ch $ID
top-02:05:52 up  3:05,  0 users,  load average:0.01, 0.02, 0.05
Tasks:   1 Total,   1 Runn ING,   0 sleeping,   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

Background run (-D), and exposed port (-p)

Docker run-d-P 127.0.0.1:33301: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 rest assured that the exit state of the container file copy out of the pit

Docker under UBUNTU14 is no service. Remove each sudo run Docker command and need to add a group:

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

UBUNTU14 Febootstrap There is no difference between the-I command dockerfile expose, Docker run--expose, Docker run-p
The expose of dockerfile is equivalent to Docker run--expose, which provides port access between container. Docker Run-p allows container external hosts to access container ports

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.