[root@docker ~]# docker Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: config Manage Docker configs container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.
1、docker start/stop/restart/kill
Start / stop / restart / kill container
Examples of operation is as follows:
[Docker the root @ ~] # Docker Start MyWeb [Docker the root @ ~] STOP # Docker MyWeb [Docker the root @ ~] # Docker the restart MyWeb [Docker the root @ ~] # -s Docker the kill the kill MyWeb parameters sent to the vessel -s # signal
2、docker run
Create and start a new container
Common parameters are as follows:
-d, = --detach to false # background container, and returns the container ID -i, = --interactive to false # container run in interactive mode, and often - T parameter used simultaneously -t, = --tty to false # give reallocate a container pseudo-terminal, and is often - I parameter used simultaneously - W , --workdir = "" , working directory specified container - name # container to specify a name -e, - the env = [] the specified environment variable the container can be used in the environment variable -m --memory = "" # container used to specify memory maximum -C, --cpu-shares = 0 , provided the container CPU weight, using the CPU sharing scenario -p, - = publish [], the container is exposed to the specified port -v, --volume = [], to mount the storage volume of the container, the container is mounted to a directory --volumes-from =[], To container mounted volumes on other containers, container mounted to a directory - the type of network used net # specified container bridge using a docker daemon designated bridge Host // container use the host's network container: NAME_or_ID > // use the Internet and other containers, shared network resources such as IP and PORT none vessel uses its own network (similar to = - net Bridge), but no configuration - link # linked to another container --restart = " nO " , the restart after the specified container stop strategy: nO: quit without restarting the container ON - failure: the failure to quit when the container (returns a non-zero value) restart always: always restart the container exit
Examples of operation is as follows:
[root @ docker ~] # docker RUN -d --name nginx busybox: Latest 3a90679ec552a00a989a9db2734044fd9a0314b35eee9b490cdcd7e763782516 # back up and running in a container named nginx, before running it will automatically go docker mirror site to download the latest image file [root @ docker ~ ] -d -p RUN # Docker 8080: 8080 busybox: Latest 3c4d6a2f19099deebc5c3f874a2c86a281076f52921fb27614654237da1cba4e # back up and running nginx named container, the container port 80 and then mapped to the physical machine 80 port [root @ docker ~] # docker run -d -v / opt / Data /: / Docker / Data -p 8080: 8080 busybox: Latest 89511e1621bb7222785deb641dfb5d7b69971e0787ecc293f47931881acd8fec # back up and running nginx named container, the container port 80 and then mapped to a physical port 80 of the machine, and the physical machine the / opt / data directory mapping to the container / Docker / Data [Docker the root @ ~] RUN # Docker -dit -v / opt / data /: / Docker / Data -p 8080: 8080 busybox: Latest / bin / SH 59961b69f80b3dab22330da30e5d4363dbd98d8bb3597b8fcfa485216f33176d [Docker the root @ ~] # Docker Exec Expediting IT 59961b69f80b / bin / SH / LS # / Docker / Data / / # # container interactive operation mode, and then performs in the container / bin / bash command
3、docker rm
Delete container
Common parameters are as follows:
-f # Forced to delete a running container
-l # delete the specified link
-v # delete the associated container and roll
Examples of operation is as follows:
[root @ Docker ~] # Docker RM -f mydocker # forcibly remove container mydocker [root @ Docker ~] # Docker RM -f dockerA dockerB # forcibly remove container dockerA, dockerB [root @ Docker ~] # Docker RM -v mydocker # delete the container and remove the container mounted data volumes
4、docker create
Create a new container but do not start it [root @ Docker ~] # Docker the Create --name myserver busybox: Latest 09b93464c2f75b7b69f83d56a9cfc23ceb50a48a9db7652ee4c27e3e2cb1961f container # create a named myserver
5、docker exec
Execute commands in the running container
Common parameters are as follows:
- D # running in the background - I # STDIN remains open -t # assigned a pseudo-terminal
Examples of operation is as follows
[Docker the root @ ~] # Docker Exec Expediting IT busybox / bin / SH /server/scripts/docker.sh Hello World !!!!!!!!!! # perform container / server / scripts / docker in interactive mode .sh script [Docker the root @ ~] # Docker Exec Expediting IT busybox / bin / SH the root b1a0703e41e7 @: / # # dispensing container in an interactive mode to a pseudo-terminal connection
6、docker ps
Listed container (running)
Common parameters are as follows:
- A list of all the container comprising # stop - F filter the display according to the conditions # - L vessel recently created lists # - n-N # lists recently created containers, N is the number - Q # display only the container ID - s # display the total file size
Examples of operation is as follows: [the root Docker @ ~] PS # Docker CONTAINER ID PORTS the STATUS the IMAGE CREATED the COMMAND NAMES e3734caa2f63 busybox: Latest "/ bin / SH" Up 2 hours 2 hours ago Member 0.0.0.0:8080->8080/tcp busybox # column running out of the container [the root Docker @ ~] Docker PS # 2 -n cONTAINER ID PORTS the STATUS the IMAGE CREATED the COMMAND NAMES e3734caa2f63 busybox: Latest "/ bin / SH" Up 2 hours 2 hours ago Member 0.0.0.0:8080->8080/ tcp busybox Busybox 81d825fbfc3b: Latest "/ bin / bash" the Created 3 hours ago Member 0.0.0.0:8080->8080/tcp vigorous_torvalds # listed two vessels recently created [root @ Docker ~] # Docker PS -a -q e3734caa2f63 81d825fbfc3b 89511e1621bb 3c4d6a2f1909 # ID display all containers
7、docker inspect
Acquiring metadata container
Common parameters are as follows:
- F # Returns the specified value or the template file format - S # Display total file size --type # Returns the type specified JSON
实例操作如下: [root@docker ~]# docker inspect f2b851facacc [ { "Id": "f2b851facacc4b43a1585cc855d464e21a64d470e9c000fec1f633e75f9706e7", "Created": "2019-12-15T10:01:46.932500174Z", "Path": "/bin/sh", "Args": [], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 7586, "ExitCode": 0, "Error": "", "StartedAt": "2019-12-15T10:01:47.870143961Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:db8ee88ad75f6bdc74663f4992a185e2722fa29573abcc1a19186cc5ec09dceb", "ResolvConfPath": "/var/lib/docker/containers/f2b851facacc4b43a1585cc855d464e21a64d470e9c000fec1f633e75f9706e7/resolv.conf", "HostnamePath": "/var/lib/docker/containers/f2b851facacc4b43a1585cc855d464e21a64d470e9c000fec1f633e75f9706e7/hostname", "HostsPath": "/var/lib/docker/containers/f2b851facacc4b43a1585cc855d464e21a64d470e9c000fec1f633e75f9706e7/hosts", "LogPath": "/var/lib/docker/containers/f2b851facacc4b43a1585cc855d464e21a64d470e9c000fec1f633e75f9706e7/f2b851facacc4b43a1585cc855d464e21a64d470e9c000fec1f633e75f9706e7-json.log", "Name": "/peaceful_ride", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": [ "/opt/data/:/docker/data/" ], ------------------------------省略部分内容 #获取容器ID为f2b851facacc的元数据信息 [root@docker ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'f2b851facacc # container to obtain an IP address f2b851facacc 172.17.0.2
8、docker logs
Get Logs container
Common parameters are as follows:
- f # trace log output - t # display timestamps - tail # display only the most recent of n log container --since # display all log a start time
Examples of operation is as follows:
[the root Docker @ ~] # Docker logs -f busybox # view a container tracking log busybox
9、docker port
Display port mapping specified container
Examples of operation is as follows:
[Docker the root @ ~] # busybox Docker Port 8080 / TCP -> 0.0.0.0:8080 port mapping information # Display container busybox
10、docker commit
Re-create a new image with the existing container
Common parameters are as follows:
- Mirror of a # submitted - c # using Dockerfile directive to create a mirror - accompanied by explanatory text when submitting m # -p # in the commit, the container is suspended
Examples of operation is as follows:
[root @ Docker ~] # Docker the commit -a "the Test" -m "mynginx" busybox busybox: v1.0 sha256: f4d667e471bc72c315bd889869fc1914936dfae2dedd2ce186ee06cad33bb4bd [root @ Docker ~] # Docker ImagesRF Royalty Free | grep busybox busybox v1.0 f4d667e471bc seconds The 24-ago Member 1.22MB # busybox container regenerate a new version of busybox: v1.0
11、docker cp
Containers for copying files between the host and the physical
Examples of operation is as follows:
[Docker the root @ ~] CP # Docker /opt/data/index.html busybox: / Docker [Docker the root @ ~] # Docker Exec Expediting IT busybox / bin / LS / Docker Data index.html # physical host / opt / data / index.html copied to / docker container busybox directory of [the root Docker @ ~] CP # Docker /opt/data/index.html busybox: /docker/index.php [Docker the root @ ~] # Docker Exec busybox Expediting IT / bin / LS / docker Data the index.php index.html # /opt/data/index.html physical host to copy the container busybox / directories and renamed the docker the index.php [the root @ ~ docker ] CP # Docker busybox: / docker / opt / [the root Docker @ ~] # LS / opt / Data Docker # copies container busybox: / docker directory to the physical host / opt / directory
12、docker login/logout
Used to log in and log out of the container mirroring warehouse
docker login # Docker log on to a mirror warehouse, if not mirrored warehouse address is specified, the default is the official repository Hub Docker
Docker Zimbabwe Logout # Docker out a mirror warehouse, if not mirrored warehouse address is specified, the default It is the official repository Docker Hub
Common parameters are as follows:
-u # login user name
-p # login password
Examples of operation is as follows:
[root @ Docker ~] # Docker the Login -u username -p password the Login Succeeded [root @ Docker ~] # Docker Zimbabwe Logout Removing the Login Credentials for https://index.docker.io/v1/ # default login and logout container mirror warehouse
13、docker pull/push
docker pull # pull or update the specified mirror from a mirrored warehouse
docker push # to upload a local mirror to mirror the warehouse, the warehouse must first log in to the mirror
Examples of operation is as follows:
[root @ Docker ~] # nginx Docker pull the Using default Tag: Latest Trying to pull Repository docker.io/library/nginx ... Latest: Pulling from docker.io/library/nginx f2aa67a397c4: Already EXISTS 3c091c23e29d: Pulling FS Layer 4a99993b8636 : pulling, FS Layer # pulling or update the specified image, output from the image repository as [the root Docker @ ~] # Docker Push busybox: V1.0.0 # image uploaded to the image repository
14、docker images
The display system of local vessel image file
Common parameters are as follows:
- A list of all # image (image-containing intermediate layer, by default, the intermediate filtered image layer); - Digests it is possible displays summary information # mirroring; - F show the condition of mirror #; - the format specified return value # template files; --no- trunc # display the full image information; -q # to display only the mirror ID.
Examples of operation is as follows:
[Docker the root @ ~] Images # Docker the REPOSITORY the TAG ID CREATED the IMAGE SIZE busybox f4d667e471bc V1.0. 8 minutes ago Member 1.22MB BitNami / Jenkins # lists all the local image
[the root Docker @ ~] # Docker Images -q 20ee805752cb 4700307f41f2 # only display container ID
[Docker the root @ ~] # Docker Images --digests the REPOSITORY the TAG ID CREATED DIGEST the IMAGE SIZE busybox v1.0 <none> f4d667e471bc 9 minutes ago 1.22MB bitnami/jenkins 2.176.3-debian-9-r5 sha256:3ed6e367edbfececb8d5eb81e1a95eacf188f2f39e629301170aa6b44d61fb92 efdd74a3f655 3 months ago 872MB [root@docker ~]# docker images --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE busybox v1.0 sha256:f4d667e471bc72c315bd889869fc1914936dfae2dedd2ce186ee06cad33bb4bd 10 minutes ago 1.22MB BitNami / Jenkins Debian-2.176.3-R5-SHA256. 9: efdd74a3f655022fedbb3ce09b4652f3b7fdf785f75ffeb1e0adb351d40b68e9 872MB. 3 months ago Member # compare the two different information can be displayed parameters
15、docker rmi
Remove Mirror
Common parameters are as follows:
-f # Forced deleted
Examples of operation is as follows:
[root@docker ~]# docker images |grep busybox REPOSITORY TAG IMAGE ID CREATED SIZE busybox v1.0 f4d667e471bc 12 minutes ago 1.22MB busybox latest db8ee88ad75f 4 months ago 1.22MB [root@docker ~]# docker rmi f4d667e471bc Untagged: busybox:v1.0 Deleted: sha256:f4d667e471bc72c315bd889869fc1914936dfae2dedd2ce186ee06cad33bb4bd Deleted: sha256:d7fda98509933c5c8f3ee5f3e774c817edcc15ee38960c27a4d19eef44253708 [root@docker ~]# docker images |grep busybox REPOSITORY TAG IMAGE ID CREATED SIZE Latest db8ee88ad75f 4 months ago Member busybox 1.22MB # delete a mirror
16、docker tag
Mark local mirror
Examples of operation is as follows:
[root @ Docker ~] # Docker ImagesRF Royalty Free | grep busybox the REPOSITORY ID TAG the IMAGE CREATED SIZE busybox Latest db8ee88ad75f 4 months ago Member 1.22MB [root @ Docker ~] # Docker Tag busybox: Latest busybox: v2 [root @ Docker ~] # Docker ImagesRF Royalty Free | grep busybox the REPOSITORY ID TAG the IMAGE CREATED SIZE busybox Latest db8ee88ad75f 4 months ago Member 1.22MB busybox v2 db8ee88ad75f 4 months ago Member 1.22MB # ID can be seen from the results of two containers is the same, just change the TAG, similar to the linux file Like the hard-linked files, both of the same inode number.
17、docker build :
Use Dockerfile create a mirror
Common parameters are as follows:
- F # Specifies the path to use Dockerfile --label = [] # Set metadata mirror using; - m # Set memory maximum --memory-swap # Swap set maximum value of the swap memory +, " -1 " represents not swap --no- cache # creation process does not use mirrored cache - pull # try the new version to update the image of - q # quiet mode, output only after a successful mirror ID - RM # Configure mirroring successfully removed the middle container - the ulimit #Ulimit configuration example as follows: [the root Docker @ ~] # Docker Build HTTPS: // github.com/nginxinc/docker-nginx/
18、docker history
View mirror of history created specified
Common parameters are as follows:
-H # printed in readable format date and image size, the default is to true;
--no the trunc # display the full-commit record;
-q # lists only commit record ID.
Examples of operation is as follows:
[root@docker ~]# docker history busybox:latest IMAGE CREATED CREATED BY SIZE COMMENT db8ee88ad75f 4 months ago /bin/sh -c #(nop) CMD ["sh"] 0B <missing> 4 months ago /bin/sh -c #(nop) ADD file:9ceca008111a4ddff… 1.22MB
19、docker info
Docker information display system, comprising a number of mirrors and the container
20、docker version
Docker display version information
Examples of operation is as follows:
[root@master ~]# docker version Client: Version: 18.06.1-ce API version: 1.38 Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:23:03 2018 OS/Arch: linux/amd64 Experimental: false Server: Engine: Version: 18.06.1-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:25:29 2018 OS/Arch: linux/amd64 Experimental: false