docker command to start container
1. Docker command line
Docker container command
Docker is an interactive tutorial designed to help users master the use of Docker command lines in order to get a quick overview of Docker. But thanks to the rapid development of Docker technology, this interactive tutorial has been unable to meet the actual needs of Docker users, so let's start a real command-line learning journey together. First, the Docker command list can be obtained by running Docker, or the Docker help command:
$ sudo docker
Docker command for running containers
In the process of Docker container technology evolving, Docker has reached 34 subcommands, with the core subcommands (for example, run) also having complex parameter configurations. By combining functional and application scenarios, the author divides the command line into 4 parts, docker commands to run a container ,allowing us to quickly overview the composition of the Docker command line:
Docker command from container
Functional Division |
Command |
Environmental information related |
- Info
- Version
|
System operation and Maintenance related |
- Attach
- Build
- Commit
- Cp
- Diff
- Export
- Images
- Import/save/load
- Inspect
- Kill
- Port
- Pause/unpause
- Ps
- Rm
- Rmi
- Run
- Start/stop/restart
- Tag
- Top
- Wait
|
Log information related |
- Events
- History
- Logs
|
Docker Hub Service Related |
- Login
- Pull/push
- Search
|
1.1 Parameter conventions
The parameters of a single character can be grouped together in a configuration, such as
Can be equated in such a way: docker container bash command
Docker run-ti--name Test BusyBox SH
1.2 Boolean
The Boolean parameter forms such as:-d=false. Note that when you declare this Boolean parameter, such as Docker run-d=true, it will simply suspend the startup container and run it in the background.
1.3 Strings and Numbers
Parameters such as--name= "" define a string that can only be defined once. The same type as-c=0 defines a number, which can only be defined once.
1.4 Background Process
The Docker daemon is a system process that is resident in the background, and it is worth noting that Docker uses the same file to support both client and background processes, where role switching is implemented through-D. This background process is used to manage containers, and Docker--help can be used to get more detailed configuration of function parameters, such as:
The Docker background process parameter list is the following table:
Parameters |
Explain |
--api-enable-cors=false |
CORS header information for open remote API calls. This interface switch provides support for top-level applications that want to develop two times. |
-B,--bridge= "" |
Mount the existing bridge device into the Docker container. Note that using none can deactivate the network in the container. |
--bip= "" |
Use CIDR addresses to set the IP of the Network Bridge. Note that this parameter and-B cannot be used together. |
-D,--debug=false |
Turn on debug mode. Example: docker-d-D |
-D,--daemon=false |
Turn on daemon mode. |
--dns=[] |
Force the container to use a DNS server. Example: docker-d--dns 8.8.8.8 |
--dns-search=[] |
Forces the container to use the specified DNS search domain name. Example: docker-d--dns-search example.com |
-E,--exec-driver= "native" |
Forces the container to use the specified run-time driver. Example: docker-d-E Lxc |
-G,--group= "Docker" |
In background run mode, assign the specified group to the appropriate UNIX socket. Note that when this parameter--group an empty string, the group information is removed. |
-G,--graph= "/var/lib/docker" |
Configure the Docker runtime root directory |
-H,--host=[] |
Specify the socket bindings in background mode, you can bind one or more tcp://host:port, Unix:///path/to/socket, fd://*, or FD://SOCKETFD. For example: $ docker-h tcp://0.0.0.0:2375 PS or $ export docker_host= "tcp://0.0.0.0:2375" $ docker PS |
--icc=true |
Enables communication for inline containers. |
--ip= "0.0.0.0" |
The default IP address used when the container binds IP |
--ip-forward=true |
Start the net.ipv4.ip_forward of the container |
--iptables=true |
Start the Docker container custom iptable rule |
--mtu=0 |
Set the MTU value for the container network, and if this parameter is not available, choose the default route MTU and set the constant value to 1500 if there is no default route. |
-P,--pidfile= "/var/run/docker.pid" |
Background process PID file path. |
-R,--restart=true |
To restart a container that was running before |
-S,--storage-driver= "" |
Forces the container to run with the specified storage driver, for example, specifying the use of Devicemapper, which can be: Docker-d-S Devicemapper |
--selinux-enabled=false |
Enable SELinux support |
--storage-opt=[] |
Configuring Storage-driven parameters |
--tls=false |
Start the TLS authentication switch |
--tlscacert= "/users/dxiao/.docker/ca.pem" |
CA-Certified Certificate file path |
--tlscert= "/users/dxiao/.docker/cert.pem" |
Certificate file path for TLS |
--tlskey= "/users/dxiao/.docker/key.pem" |
Key file path for TLS |
--tlsverify=false |
Using TLS and verifying the background process and client communication |
-V,--version=false |
Display version Information |
Note that the startup parameter with [] can be specified more than once, for example
$ docker run-a stdin-a stdout-a stderr-i-T Ubuntu/bin/bash
2. Docker command Line Quest 2.1 Environmental information related
Info
How to use: Docker info
Example:
[email protected] docker]$ sudo docker-d infocontainers:0images:32storage driver:devicemapper Pool name:docker-252:1 -130159-pool Data File:/var/lib/docker/devicemapper/devicemapper/data Metadata file:/var/lib/docker/devicemapper/ Devicemapper/metadata data Space used:1616.9 MB data space total:102400.0 MB metadata space used:2.4 Mb metadata Space total:2048.0 mbexecution driver:native-0.2kernel version:3.11.10-301.fc20.x86_64debug mode (server): FalseDebug mode ( Client): Truefds:11goroutines:14eventslisteners:0init sha1:2c5adb59737b8a01fa3fb968519a43fe140bc9c9init Path:/usr /libexec/docker/dockerinitsockets: [fd://]
Instructions for use:
This command is useful when developers report bugs, and together with Docker vesion, you can use this command to provide local configuration information at any time, allowing Docker developers to quickly locate the problem.
Version
How to use: Docker version
Instructions for use:
Displays the version number of the Docker, the API version number, the Git commit, the go version number of the Docker client and the background process.
2.2 System operation and maintenance related
Attach
How to use: Docker attach [OPTIONS] CONTAINER
Example:
$ id=$ (sudo docker run-d ubuntu/usr/bin/top-b) $ sudo docker attach $IDtop -17:21:49 up 5:53, 0 users, load average:0.63, 1.15, 0.78Tasks: 1 Total, 1 running, 0 sleeping, 0 stopped, 0 zombie%cpu (s): 1.0 us, 0.7 sy, 0.0 ni, 97.7 ID, 0.7 wa, 0.0 hi, 0.0 si, 0.0 stkib Mem: 2051644 Total, 723700 used, 1327944 free, 33032 Bufferskib swaps: 0 Total, 0 used, 0 free. 565836 cached Mem PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND 1 root 0 19748 1008 R 0.0 0.1 0:00.04 top$ sudo docker stop $ID
Instructions for use:
Use this command to mount a container that is running in the background and use this command to observe the health of the process in the container at any time during the development of the application. This command is a very useful command for developers in the context of developing applications.
Build
How to use: Docker build [OPTIONS] PATH | URL | -
Example:
$ docker build. Uploading context 18.829 mbuploading contextstep 0:from busybox---> 769b9341d937step 1:cmd echo Hello World--- ; Using Cache---> 99cc1ad10469successfully built 99cc1ad10469
Instructions for use:
This command is a command to build a new image from the source code. Because the image is layered, the most critical base image is how the user is concerned, and the Docker official document gives the construction method, please refer to here.
Commit
How to use: Docker commit [OPTIONS] CONTAINER [Repository[:tag]]
Example:
$ sudo docker psID IMAGE COMMAND CREATED STATUS portsc3f279d17e0a ubuntu:12.04 /bin/ Bash 7 days ago up hours197387f1b436 ubuntu:12.04 /bin/bash 7 days ago up hours$ Docker commit c3f279d17e0a svendowideit/testimage:version3f5283438590d$ docker images | headrepository TAG ID CREATED VIRTUAL sizesvendowideit/testimage version3 f5283438590d seconds ago 335.7 MB
Instructions for use:
The purpose of this command is to submit the modified container to the new image, and then export the Imange to be distributed to other scenarios for debugging purposes. The official Docker recommendation is that when you have finished debugging the image, you should write a new Dockerfile file to maintain the image. The commit command is only a secondary command that temporarily creates a imange.
Cp
How to use: CP Container:path Hostpath
Instructions for use:
Use the CP to copy the files from the container to the host. This command, in the case of developer application development, will require the need to copy the results of the running program, and this CP command can be used in this situation.
Diff
How to use: Docker diff CONTAINER
Example:
$ sudo docker diff 7bb0e258aefec/deva/dev/kmsgc/etca/etc/mtaba/goa/go/srca/go/src/github.coma/go/src/github.com/do Tcloud ....
Instructions for use:
Diff lists List of file status changes (A-add, D-delete, C-change) in 3 containers. The debug instructions needed to build the image.
Export
How to use: Docker export CONTAINER
Example:
$ sudo docker export Red_panda > Latest.tar
Instructions for use:
The container system files are packaged and exported for easy distribution to other scenarios.
Images
How to use: Docker images [OPTIONS] [NAME]
Example:
$ sudo docker images | Headrepository TAG IMAGE ID CREATED VIRTUAL size<none> <none> 77af4d6b9913 hours ago 1.089 gbcommittest LAT est b6fa739cedf5 hours ago 1.089 gb<none> <none> 78a85c484f71 The hours ago 1.089 gb$ Docker latest 30557a29 D5ab hours 1.089 gb<none> <none> 0124422dd9f9 hours ago 1.089 gb<none> <none> 18ad6fad34 Hours ago 1.082 gb<none> <none> f9f1e26352f0 hours ago 1.089 gbtryout latest 2629d1fa0b81 All Hours AG o 131.5 mb<none> <none> 5ed6274db6ce hours ago 1.089 GB
Instructions for use:
Docker image is a multi-layered structure that displays only the topmost image by default. The middle tier that is not displayed defaults to the ability to increase reusability, reduce disk usage, and speed up build builds, which the general user does not need to care about.
Import/save/load
How to use:
Docker import url|-[Repository[:tag]]docker save Imagedocker Load
Instructions for use:
This set of commands is a very critical command for system Operation Virial. Load (two methods: import, load), export (one method: Save) container system files.
Inspect
How to use:
Docker Inspect container| IMAGE [container| IMAGE ...]
Example:
$ sudo docker inspect--format= ' {{. Networksettings.ipaddress}} ' $INSTANCE _id
Instructions for use:
A command to view the container run-time details. The complete build information for an image or container can be implemented with this command.
Kill
How to use:
Docker kill [OPTIONS] CONTAINER [CONTAINER ...]
Instructions for use:
The process of killing the container.
Port
How to use:
Docker Port CONTAINER Private_port
Instructions for use:
To print the NAT mapping relationship of the host port to the port exposed by the container
Pause/unpause
How to use:
Docker Pause CONTAINER
Instructions for use:
Pauses and restores all processes in the container using Cgroup's freezer order. For detailed freezer features, please refer to the official documentation.
Ps
How to use:
Docker PS [OPTIONS]
Example:
$ docker pscontainer ID IMAGE COMMAND CREATED STATUS PORTS names4c01db0b339c Ubuntu : 12.04 bash seconds ago up seconds webappd7886598dbe2 crosbymichael/redis:latest /redis-server--dir minutes ago up minutes 6379/tcp redis,webapp/db
Instructions for use:
Docker PS prints out the running container, and the Docker ps-a prints out all the containers that were running.
Rm
How to use:
Docker RM [OPTIONS] CONTAINER [CONTAINER ...]
Example:
$ sudo docker Rm/redis/redis
Instructions for use:
Deletes the specified container.
Rmi
How to use:
Docker rmi IMAGE [Image ...]
Example:
$ sudo docker imagesrepository TAG IMAGE ID CREATED SIZEtest1 latest fd484f19954f All seconds ago 7 B (Virtual 4.964 MB) tes T latest fd484f19954f seconds ago 7 B (Virtual 4.964 MB) test2 latest fd484f19954f $ seconds ago 7 B (Virtual 4.964 MB) $ sudo docker rmi fd484f19954ferror:conflict, cannot delete image fd484f19954f because it's tagged in multiple repositor IES2013/12/11 05:47:16 error:failed To remove one or more images$ sudo docker rmi test1untagged:fd484f19954f4920da7ff372 b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8$ sudo docker rmi test2untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8$ sudo docker imagesrepository TAG IMAGE ID CREATED Sizetest latest fd484f19954f seconds ago 7 B (Virtual 4.964 MB) $ sudo docker rmi testuntagged:fd484f19954f4920da7ff372 B5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8deleted: Fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
Instructions for use:
Specifies that the image file be deleted.
Run
How to use:
Docker run [OPTIONS] IMAGE [COMMAND] [ARG ...]
Example:
$ sudo docker run--cidfile/tmp/docker_test.cid ubuntu echo "Test"
Instructions for use:
This command is a core command that can be configured with up to 28 parameters. A detailed explanation can be listed by Docker run--help. The official documentation mentions the Issue 2702: "Lxc-start:permission denied-failed to mount" could indicate a permissions problem with AppArmor. has been resolved in the latest version of Dcoker.
Start/stop/restart
How to use:
Docker start CONTAINER [CONTAINER ...]
Instructions for use:
This set of commands can be turned on (two: Start, restart), stop (A: stop) a container.
Tag
How to use:
Docker tag [OPTIONS] image[:tag] [Registryhost/][username/]name[:tag]
Instructions for use:
The combination uses the user name, image name, and tag name to organize and manage the image.
Top
How to use:
Docker top CONTAINER [PS OPTIONS]
Instructions for use:
Displays the processes running inside the container.
Wait
How to use:
Docker wait CONTAINER [CONTAINER ...]
Instructions for use:
Blocks other calling methods on the specified container until the container stops and exits blocking.
2.3 Log information related
Events
How to use:
Docker events [OPTIONS]
Instructions for use:
Print container real-time system events.
History
How to use:
Docker history [OPTIONS] IMAGE
Example:
$ docker History dockerimage CREATED CREATED by size3e23a5875458790b7a806f95f7ec0d0b2a5c1659bfc899c89f939f6d5b8f7094 8 Days Ago/bin/sh-c # (NOP) ENV lc_all=c.utf-8 0 B8578938dd17054dce7993d21de79e96a037400e8d28e15e7290fea4f65128a36 8 days Ago/bin/sh-c dpkg-reconfigure locales && locale-gen c.utf-8 &&/usr/sbin/update-locale lang=c.utf-8 1.2 Mbbe51b77efb42f67a5e96437b3e102f81e0a1399038f77bf28cea0ed23a65cf60 8 days ago/bin/sh-c apt-get update && Apt-get install-y git libxml2-dev python build-essential make gcc python-dev locales python-pip 338.3 mb4b137612be55ca697 76c7f30c2d2dd0aa2e7d72059820abf3e25b629f887a084 6 weeks Ago/bin/sh-c # (NOP) ADD jessie.tar.xz in/121 mb750d58736b4b6cc 0f9a9abe8f258cef269e3e9dceced1146503522be9f985ada 6 weeks Ago/bin/sh-c # (NOP) maintainer Tianon Gravi <[email Protected]>-mkimage-debootstrap.sh-t jessie.tar.xz Jessie Http://http.debian.net/debian 0 B511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 9 months ago 0 B
Instructions for use:
Prints the history of the image command line for each layer in the specified image.
Logs
How to use:
Docker logs CONTAINER
Instructions for use:
Batch print out the running log of the process in the container.
2.4 Dcoker Hub Service related
Login
How to use:
Docker login [OPTIONS] [SERVER]
Instructions for use:
Log in to the hub service.
Pull/push
How to use:
Docker Push Name[:tag]
Instructions for use:
Share image to hub service or self-service registry service with this command.
Search
How to use:
Docker Search term
Instructions for use:
Search for shared image by keyword.
3. Summary
The full understanding of Docker commands can be enhanced through the detailed explanation of the above Docker command line. Given the rapid evolution of the Docker command line, the reader can refer to the official command line to interpret the document to update the appropriate command-line explanations. In addition, through the above Docker command line analysis, you can know that the Docker command line architecture design is characterized by the client and server running files are the same file, the internal implementation code should be the design of reuse. I hope that developers in the development of similar command-line applications to reference such a design, reduce the complexity of front and rear fault tolerance.
Reference documents
[1] https://docs.docker.com/reference/commandline/cli/
[2] Https://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
[3] Https://en.wikipedia.org/wiki/CIDR_notation#CIDR_notation
Docker (ii): Docker command-line Quest