Detailed Docker commands

Source: Internet
Author: User
Tags diff docker ps docker cp docker hub docker run docker registry

# Docker--help
Usage:docker [OPTIONS] COMMAND [arg ...]
Docker daemon [--help | ...]
Docker [-H |--help |-V |--version]

A self-sufficient runtime for containers.

Options:

--config=~/.docker location of the client config files
-D,--debug=false Enable debug mode
-H,--host=[] Daemon socket (s) to connect to
-H,--help=false Print usage
-L,--log-level=info Set the logging level
--tls=false use TLS; Implied by--tlsverify
--TLSCACERT=~/.DOCKER/CA.PEM Trust Certs signed only by the This CA
--tlscert=~/.docker/cert.pem Path to TLS certificate file
--tlskey=~/.docker/key.pem Path to TLS key file
--tlsverify=false use TLS and verify the remote
-V,--version=false Print version information and quit

Commands:
Attach attach to a running container
--Attaching the terminal to the container
1> running an interactive container
[email protected] ~]# Docker run-i-T Centos/bin/bash
[Email protected]/]#
2> View the status of the container on another window
[email protected] ~]# Docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
D4a75f165ce6 CentOS "/bin/bash" 5 seconds ago up 5 seconds Cranky_mahavira
3> exit the container running in the first step
[[Email protected]/]# exit
Exit
4> View the status of the container
[email protected] ~]# Docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
D4a75f165ce6 CentOS "/bin/bash" 2 minutes ago Exited (0) seconds ago Cranky_mahavira
It can be seen that the state of this container is exited, so how do you run the container again? You can use the Docker start command
5> Run the container again
[[email protected] ~]# Docker start Cranky_mahavira
Cranky_mahavira
6> View the status of the container again
[email protected] ~]# Docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
D4a75f165ce6 CentOS "/bin/bash" 6 minutes ago up seconds Cranky_mahavira
Because the container is interactive, we can now use the Attach command when we find that no specific terminal can interact with it.
7> interacting with the Attach command
[email protected] ~]# Docker attach Cranky_mahavira
[Email protected]/]#

Build build a image from a Dockerfile
--Create a mirror from dockerfile

Commit Create a new image from a container ' s changes
--Create a local mirror from a container
Note: If you are pushing to the Docker hub, be aware of the naming of the generated mirrors
[email protected] ~]# Docker commit CENTOS_V1 CENTOS:V1
68ad49c999496cff25fdda58f0521530a143d3884e61bce7ada09bdc22337638
[email protected] ~]# Docker push CENTOS:V1
You cannot push a "root" repository. Rename your repository to <user>/<repo> (ex: <user>/centos)
Not with CENTOS:V1, because when it pushes to the Docker hub, it is pushed to the appropriate user and the user name must be specified. For example, if my user name is Ivictor, the newly generated local image is named:
Docker push Victor/centos:v1, where V1 is tag, can not be written, default is latest

CP Copy files/folders from a container to a hostdir or to STDOUT
--Copy files between host and container
The use of CP is as follows:
Usage:docker CP [OPTIONS] Container:path localpath|-
Docker CP [OPTIONS] localpath|-Container:path
such as: container mysql/usr/local/bin/exists docker-entrypoint.sh file, can copy to host in the following way
# docker CP Mysql:/usr/local/bin/docker-entrypoint.sh/root
After the modification is complete, copy the file back to the container
# docker cp/root/docker-entrypoint.sh mysql:/usr/local/bin/

Create Create a new container
--Create a new container, note that at this point, the status of the container is just created

Diff Inspect Changes on a container ' s filesystem
--look at the changed files in the container, take my MySQL container as an example
[email protected] ~]# Docker diff mysqldb
C/root
A/root/.bash_history
A/test1.txt
A/test.tar
A/test.txt
C/run
C/run/mysqld
A/run/mysqld/mysqld.pid
A/run/mysqld/mysqld.sock
It is not difficult to see, C corresponds to the directory, a corresponding to the file

Events Get Real Time events from the server
--real-time output of Docker server-side events, including container creation, startup, shutdown, etc.
Such as:
[email protected] ~]# Docker events
2015-09-08t17:40:13.000000000+08:00 d2a2ef5ddb90b505acaf6b59ab43eecf7eddbd3e71f36572436c34dc0763db79: (From WordPress) Create
2015-09-08t17:40:14.000000000+08:00 d2a2ef5ddb90b505acaf6b59ab43eecf7eddbd3e71f36572436c34dc0763db79: (From WordPress) die
2015-09-08t17:42:10.000000000+08:00 839866a338db6dd626fa8eabeef53a839e4d2e2eb16ebd89679aa722c4caa5f7: (from MySQL ) Start

EXEC Run a command in a running container
--To perform other tasks after the container is started
The EXEC command allows you to create two kinds of tasks: back-end tasks and interactive tasks
Back-up tasks: Docker exec-d cc Touch 123 where CC is the container name
Interactive tasks:
[email protected] ~]# Docker exec-i-T Cc/bin/bash
[Email protected]:/# ls
Bin Boot Dev etc home lib lib64 media mnt opt proc root run sbin SRV sys tmp usr var

Export export a container ' s filesystem as a tar archive
--Package The container's file system into a tar file
There are two ways of doing this:
Docker Export-o Mysqldb1.tar MySQLdb
Docker Export MySQLdb > Mysqldb.tar

History Show The history of an image
--show the process of image production, equivalent to Dockfile

Images List Images
--List all mirrors on this machine

Import Import the contents from a tarball to create a filesystem image
--Create a new image based on the contents of the tar file, as opposed to the previous export command
[email protected] ~]# Docker import Mysqldb.tar mysql:v1
Eb81de183cd94fd6f0231de4ff29969db822afd3a25841d2dc9cf3562d135a10
[email protected] ~]# Docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
MySQL v1 eb81de183cd9 seconds ago 281.9 MB

Info Display system-wide Information
--View Docker's system Information
[[email protected] ~]# Docker info
Containers:3--There are currently 3 containers
images:298
Storage Driver:devicemapper
Pool Name:docker-253:0-34402623-pool
Pool blocksize:65.54 KB
backing FILESYSTEM:XFS
Data File:/dev/loop0
Metadata File:/dev/loop1
Data Space used:8.677 GB-corresponds to the following data loop file size
Data Space total:107.4 GB
Data Space available:5.737 GB
Metadata Space used:13.4 MB--corresponds to the following Metadata loop file size
Metadata Space total:2.147 GB
Metadata Space available:2.134 GB
Udev Sync Supported:true
Deferred removal Enabled:false
Data Loop file:/var/lib/docker/devicemapper/devicemapper/data
Metadata Loop file:/var/lib/docker/devicemapper/devicemapper/metadata
Library Version:1.02.93-rhel7 (2015-01-28)
Execution driver:native-0.2
Logging Driver:json-file
Kernel version:3.10.0-229.el7.x86_64
Operating System:centos Linux 7 (Core)
Cpus:2
Total memory:979.7 MiB
Name:localhost.localdomain
Id:tfvb:bxgq:vvoc:k2dj:lece:2hnk:23b2:levf:p3iq:l7d5:ng2v:uknl
Warning:bridge-nf-call-iptables is disabled
Warning:bridge-nf-call-ip6tables is disabled

Inspect Return low-level information on a container or image
--Used to view the container's configuration information, including container name, environment variables, Run command, host configuration, network configuration, data volume configuration, and so on.

Kill Kill a Running container
--Forced termination of the container
With regard to the difference between stop and kill, the Docker Stop command sends a SIGTERM signal to the process in the container, and the default behavior is to cause the container to exit, of course,
The program in the container can capture the signal and handle it on its own, for example by choosing to ignore it. Docker Kill is the process of sending a sigkill signal to the container, which will cause the container to exit inevitably.

Load load an image from a tar archive or STDIN
--In contrast to the following Save command, import the image packaged by the following Sava command into the load command

Login Register or log in to a Docker registry
--Login to your Docker register and need to have a registered account with the Docker hub
[email protected] ~]# Docker Login
Username:ivictor
Password:
Email:xx[email protected]
Warning:login Credentials Saved In/root/.docker/config.json
Login succeeded

Logout Log out from a Docker registry
--Sign Out
[email protected] ~]# Docker Logout
Remove login Credentials for https://index.docker.io/v1/

Logs Fetch the logs of a container
--Used to view the log of the container, which outputs data to the standard output as a log output to the terminal of the Docker logs command. Often used in back-end containers

Pause pause all processes within a container
--pauses all processes within the container,
At this point, through Docker stats you can observe that the resource usage is fixed at this time,
The further output of the log is also not observed through Docker logs-f.

Port List port mappings or a specific mapping for the CONTAINER
--mapping of the output container port to the host port
Such as:
[[email protected] ~]# Docker Port Blog
80/TCP-0.0.0.0:80
The internal port 80 of the container blog is mapped to the 80 port of the host, so that the service provided by the container blog can be viewed from the host's 80 port

PS List Containers
--Lists all containers, where Docker PS is used to view the running container, and ps-a is used to view all containers.

Pull pull, an image, or a repository from a registry
--Download the image from the Docker hub

Push push a image or a repository to a registry
--Upload the local image to the Docker hub
If you want to log on with Docker login first, you will be reported the following error
[email protected] ~]# Docker push IVICTOR/CENTOS:V1
The push refers to a repository [Docker.io/ivictor/centos] (Len:1)
Unauthorized:access to the requested resource are not authorized

Rename Rename a container
--Change the name of the container

Restart restart a running container
--Restart Container

RM Remove one or more containers
--Delete the container, note that you cannot delete a running container, you must first stop it with Docker stop or Docker kill.
Of course you can force the deletion, you must add the-f parameter
If you want to remove all containers at once, you can use Docker rm-f ' Docker ps-a-Q ', where-Q refers to only the ID of the container listed

RMI Remove one or more images
--delete Mirror

Run Run a command in a new container
--Let the container be created immediately into the running state, which is equivalent to Docker create container before using Docker start to start the container

Save save an image (s) to a tar archive
--Package The image, as opposed to the load command above
Such as:
Docker Save-o Nginx.tar Nginx

Search Search the Docker Hub for images
--Search for mirrors from the Docker hub

Start start one or more stopped containers
--Start container

Stats Display a live stream of container (s) Resource usage statistics
--Dynamic display of the resource consumption of the container, including: CPU, memory, network I/O

Stop stop a running container
--Stop a running container

Tag tag an image into a repository
--Renaming the image

Top Display The running processes of a container
--View the running processes in the container

Unpause unpause all processes within a container
--Restores the suspended process within the container, as opposed to the pause parameter

Version Show the Docker version information
--View the version of Docker

Wait Block until a container stops, then print its exit code
--Capture the exit code when the container stops
After executing this command, the command will "hang" at the current terminal until the container stops and the exit code for the container will be printed.

Run ' Docker command--help ' For more information on a command.

Detailed Docker commands

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.