docker 命令
docker 命令
执行docker --help既可查询命令的使用方法
[root@node1 conf.d]# docker --help Usage: docker [OPTIONS] COMMAND [arg...] docker [ --help | -v | --version ] A self-sufficient runtime for containers. Options: --config=~/.docker Location of client config files -D, --debug Enable debug mode -H, --host=[] Daemon socket(s) to connect to -h, --help Print usage -l, --log-level=info Set the logging level --tls Use TLS; implied by --tlsverify --tlscacert=~/.docker/ca.pem Trust certs signed only by this CA --tlscert=~/.docker/cert.pem Path to TLS certificate file --tlskey=~/.docker/key.pem Path to TLS key file --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Commands: attach Attach 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 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 a container, image or task 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 network Manage Docker networks node Manage Docker Swarm nodes 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 a container 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 service Manage Docker services 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 swarm Manage Docker Swarm tag Tag an image into a repository 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 volume Manage Docker volumes wait Block until a container stops, then print its exit code Run 'docker COMMAND --help' for more information on a command. [root@node1 conf.d]#
下面是每个子命令的使用方法及案例
[root@node1 conf.d]# docker version Client: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-68.gitec8512b.el7.centos.x86_64 Go version: go1.8.3 Git commit: ec8512b/1.12.6 Built: Mon Dec 11 16:08:42 2017 OS/Arch: linux/amd64 Server: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-68.gitec8512b.el7.centos.x86_64 Go version: go1.8.3 Git commit: ec8512b/1.12.6 Built: Mon Dec 11 16:08:42 2017 OS/Arch: linux/amd64 [root@node1 conf.d]#
[root@node1 conf.d]# docker inof docker: 'inof' is not a docker command. See 'docker --help'. [root@node1 conf.d]# docker info Containers: 14 Running: 5 Paused: 0 Stopped: 9 Images: 77 Server Version: 1.12.6 Storage Driver: devicemapper Pool Name: docker-253:0-33586272-pool Pool Blocksize: 65.54 kB Base Device Size: 10.74 GB Backing Filesystem: xfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 3.39 GB Data Space Total: 107.4 GB Data Space Available: 47.23 GB Metadata Space Used: 8.716 MB Metadata Space Total: 2.147 GB Metadata Space Available: 2.139 GB Thin Pool Minimum Free Space: 10.74 GB Udev Sync Supported: true Deferred Removal Enabled: true Deferred Deletion Enabled: true Deferred Deleted Device Count: 0 Data loop file: /var/lib/docker/devicemapper/devicemapper/data WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device. Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.135-RHEL7 (2016-09-28) Logging Driver: journald Cgroup Driver: systemd Plugins: Volume: local Network: bridge null host overlay Swarm: inactive Runtimes: docker-runc runc Default Runtime: docker-runc Security Options: seccomp Kernel Version: 3.10.0-514.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 Number of Docker Hooks: 3 CPUs: 16 Total Memory: 15.5 GiB Name: node1 ID: MS2K:47EM:CWQ3:C4DK:FN6W:G5U2:QU4V:74BN:N57K:NZ32:7GLT:MNDV Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Insecure Registries: 192.168.1.5:5000 127.0.0.0/8 Registries: docker.io (secure) [root@node1 conf.d]#
查询镜像 语法 docker search nginx [root@node1 tmp]# docker search nginx INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/nginx Official build of Nginx. 7751 [OK] docker.io docker.io/jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1237 [OK] docker.io docker.io/richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 500 [OK] docker.io docker.io/jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as... 289 [OK] docker.io docker.io/kong Open-source Microservice & API Management ... 152 [OK] docker.io docker.io/webdevops/php-nginx Nginx with PHP-FPM 94 [OK] docker.io docker.io/kitematic/hello-world-nginx A light-weight nginx container that demons... 88 docker.io docker.io/bitnami/nginx Bitnami nginx Docker Image 44 [OK] docker.io docker.io/linuxserver/nginx An Nginx container, brought to you by Linu... 30 docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 24 [OK] docker.io docker.io/tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 15 [OK] docker.io docker.io/wodby/drupal-nginx Nginx for Drupal container image 9 [OK] docker.io docker.io/blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 8 [OK] docker.io docker.io/nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes 8 docker.io docker.io/webdevops/nginx Nginx container 8 [OK] docker.io docker.io/centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 5 docker.io docker.io/1science/nginx Nginx Docker images that include Consul Te... 4 [OK] docker.io docker.io/behance/docker-nginx Provides base OS, patches and stable nginx... 2 [OK] docker.io docker.io/pebbletech/nginx-proxy nginx-proxy sets up a container running ng... 2 [OK] docker.io docker.io/bbtsoftwareag/nginx-proxy-unrestricted-requestsize jwilder/nginx-proxy with unrestricted clie... 1 [OK] docker.io docker.io/toccoag/openshift-nginx Nginx reverse proxy for Nice running on sa... 1 [OK] docker.io docker.io/travix/nginx NGinx reverse proxy 1 [OK] docker.io docker.io/goodguide/nginx-application-proxy No-configuration Nginx reverse proxy for a... 0 [OK] docker.io docker.io/mailu/nginx Mailu nginx frontend 0 [OK] docker.io docker.io/ppc64le/nginx Official build of Nginx. 0 [root@node1 tmp]#
拉去一个镜像到本地
语法
docker pull 镜像:版本
docker pull nginx
显示本地所有的镜像 -q只列出镜像ID -a列出所有中间层镜像 [root@node1 tmp]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.1.5:5000/tomcat-xcweb vtest19 fad55cf9ca9c 7 seconds ago 603.7 MB 192.168.1.5:5000/tomcat-xcweb vtest18 e977adf9da5e 14 minutes ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest17 509be986e810 28 minutes ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest16 6a5d1e6c2989 2 hours ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest15 3c3178009893 2 hours ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest14 3aabe82f43fc 3 hours ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest13 8a86599e4a86 3 hours ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest12 fc9d0ca94c67 4 hours ago 620.4 MB 192.168.1.5:5000/tomcat-xcweb vtest11 88950979cc09 4 hours ago 603.7 MB 192.168.1.5:5000/tomcat-xcweb vtest10 82e88fe87d98 5 hours ago 603.7 MB 192.168.1.5:5000/tomcat-xcweb vtest9 d99103a77b4b 7 hours ago 603.7 MB 192.168.1.5:5000/tomcat-xcweb vtest8 0f721ff406c8 23 hours ago 603.7 MB 192.168.1.5:5000/tomcat-xcweb vtest7 2290243e4492 25 hours ago 6 [root@node1 tmp]# docker images -q fad55cf9ca9c e977adf9da5e 509be986e810 6a5d1e6c2989 3c3178009893 3aabe82f43fc 8a86599e4a86 fc9d0ca94c67 88950979cc09 82e88fe87d98 d99103a77b4b 0f721ff406c8 2290243e4492 464c4f58a062 0316533e8356 3bdb947133ee ad96e58dda4f ecc512411925 06f40742af94 c4ea572b3562 cdd18ac0ae6b 4d2df61acb62
查看运行的docker容器 默认只查看在运行的容器 -a列出所有的包括停止的容器 -q只列出容器的ID -s显示容器的大小 [root@node1 tmp]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 843e3b974e1b 192.168.1.5:5000/tomcat-xcweb:vtest19 "/bin/sh -c '\"/usr/lo" 5 minutes ago Up 5 minutes 0.0.0.0:20000->8080/tcp gigantic_shockley 8920f004a65f 192.168.1.5:5000/tomcat-rms:v1 "/bin/sh -c '\"/usr/lo" 31 hours ago Up 31 hours k8s_rms.de2f2a36_rms-5ba023ebf408f30425cda30816b424cc-9k1cj_default_35ea0931-fd97-11e7-a77b-d8d3855c4630_3cb3d30e 10741d7534e5 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 31 hours ago Up 31 hours k8s_POD.24f70ba9_rms-5ba023ebf408f30425cda30816b424cc-9k1cj_default_35ea0931-fd97-11e7-a77b-d8d3855c4630_73afe8d3 210db401f65e 192.168.1.5:5000/tomcat-rmsweb:400 "/bin/sh -c '\"/usr/lo" 2 days ago Up 2 days 0.0.0.0:20001->8080/tcp small_blackwell 20c1bc4aef41 192.168.1.5:5000/tomcat-cmsweb:300 "/bin/sh -c '\"/usr/lo" 2 days ago Up 2 days 0.0.0.0:20002->8080/tcp big_jang [root@node1 tmp]# [root@node1 tmp]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 843e3b974e1b 192.168.1.5:5000/tomcat-xcweb:vtest19 "/bin/sh -c '\"/usr/lo" 5 minutes ago Up 5 minutes 0.0.0.0:20000->8080/tcp gigantic_shockley e5071339b600 192.168.1.5:5000/tomcat-xcweb:vtest17 "/bin/sh -c '\"/usr/lo" 27 minutes ago Exited (130) 26 minutes ago nostalgic_euclid 8920f004a65f 192.168.1.5:5000/tomcat-rms:v1 "/bin/sh -c '\"/usr/lo" 31 hours ago Up 31 hours k8s_rms.de2f2a36_rms-5ba023ebf408f30425cda30816b424cc-9k1cj_default_35ea0931-fd97-11e7-a77b-d8d3855c4630_3cb3d30e 10741d7534e5 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 31 hours ago Up 31 hours k8s_POD.24f70ba9_rms-5ba023ebf408f30425cda30816b424cc-9k1cj_default_35ea0931-fd97-11e7-a77b-d8d3855c4630_73afe8d3 210db401f65e 192.168.1.5:5000/tomcat-rmsweb:400 "/bin/sh -c '\"/usr/lo" 2 days ago Up 2 days 0.0.0.0:20001->8080/tcp small_blackwell 20c1bc4aef41 192.168.1.5:5000/tomcat-cmsweb:300 "/bin/sh -c '\"/usr/lo" 2 days ago Up 2 days 0.0.0.0:20002->8080/tcp big_jang 2fb1a7a18207 54808f37335e "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago stoic_roentgen b3ba619d9f72 c2b8167c646e "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago dreamy_bassi d1d3153ee1b2 525e59852ca0 "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago jolly_hugle 435e05a47c56 3551621072f1 "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago nauseous_einstein 3ec5c34e68ce fe56d84b2ddd "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago prickly_stonebraker 8fa8a7a0ee0e 192.168.1.5:5000/tomcat-xc:v1 "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago high_lamport 04e17c19bfb4 d8de7c54837f "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago determined_saha 0b6630fdb55c 192.168.1.5:5000/tomcat-xc:v1 "/bin/sh -c '\"/usr/lo" 2 days ago Exited (130) 2 days ago suspicious_brattain [root@node1 tmp]# [root@node1 tmp]# docker ps -q 8920f004a65f 10741d7534e5 210db401f65e 20c1bc4aef41 [root@node1 tmp]# [root@node1 tmp]# docker ps -s CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 219f6230da1f 192.168.1.5:5000/tomcat-xcweb:vtest20 "/bin/sh -c '\"/usr/lo" 18 seconds ago Up 6 seconds 0.0.0.0:20000->8080/tcp dreamy_roentgen 40.28 kB (virtual 620.4 MB) 8920f004a65f 192.168.1.5:5000/tomcat-rms:v1 "/bin/sh -c '\"/usr/lo" 31 hours ago Up 31 hours k8s_rms.de2f2a36_rms-5ba023ebf408f30425cda30816b424cc-9k1cj_default_35ea0931-fd97-11e7-a77b-d8d3855c4630_3cb3d30e 81.25 kB (virtual 602 MB) 10741d7534e5 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 31 hours ago Up 31 hours k8s_POD.24f70ba9_rms-5ba023ebf408f30425cda30816b424cc-9k1cj_default_35ea0931-fd97-11e7-a77b-d8d3855c4630_73afe8d3 0 B (virtual 208.6 MB) 210db401f65e 192.168.1.5:5000/tomcat-rmsweb:400 "/bin/sh -c '\"/usr/lo" 2 days ago Up 2 days 0.0.0.0:20001->8080/tcp small_blackwell 42.54 kB (virtual 602 MB) 20c1bc4aef41 192.168.1.5:5000/tomcat-cmsweb:300 "/bin/sh -c '\"/usr/lo" 2 days ago Up 2 days 0.0.0.0:20002->8080/tcp big_jang 2.692 MB (virtual 604.8 MB) [root@node1 tmp]#
删除本地镜像 默认有运行的容器占用镜像是删除不了的 -f强制删除 也可以指定镜像的ID删除 [root@node1 tmp]# docker rmi -f 192.168.1.5:5000/tomcat-xcweb:vtest1 Untagged: 192.168.1.5:5000/tomcat-xcweb:vtest1 Deleted: sha256:06f40742af94c8a889c64abf2cd227d940cd6e24bdee2cefca6b402921c1e808 Deleted: sha256:903d631c45f2f09c7e5831a7d1adf529e4f8878a2edf58d3e11ecea49357e98b Deleted: sha256:ca5e1db2d117afaa95c7ee1c8a52ee770b407c922397359b7e6fbc4c285380b2 Deleted: sha256:5b465e1d5085a0b04456520afd8df488e258b90140318a6a4eb3dcb5a5c42279 Deleted: sha256:3a66d6738d633b5e1a55e14980d54aebce6cc07429c1ca698df52596149342e3 [root@node1 tmp]# docker rmi -f ecc512411925 Untagged: 192.168.1.5:5000/tomcat-xcweb:vtest2 Deleted: sha256:ecc5124119255c76403b79d5444269c362a1b5a3791e16db5e610f7364eadcd0 Deleted: sha256:ad44d4a1dd3f8385c8bd687d05e2d94764eecf5d554d5906a39b2256eec5175a Deleted: sha256:88609b4eaf4be004b482a8a0cb4620ba0efc41a10be660c32a273a34e8995182 Deleted: sha256:ac62908d9750a010bfd49ef62772555fee739b46a7786cbf193883b027f2ff0d Deleted: sha256:7e0699192b9ff03e09804696da88ce68dafdc38befe5e6bab0496790db4d0a27 [root@node1 tmp]#
删除一个容器默认在运行的容器是删除不掉的 -f强制删除 [root@node1 tmp]# docker rm -f 0b6630fdb55c 0b6630fdb55c [root@node1 tmp]#
启动一个已经停止了的容器
[root@node1 tmp]# docker start 435e05a47c56
435e05a47c56
停止一个正在运行的容器
[root@node1 tmp]# docker stop 435e05a47c56
435e05a47c56
显示指定镜像的创建历史 [root@node1 tmp]# docker history 192.168.1.5:5000/tomcat-cmsweb:300 IMAGE CREATED CREATED BY SIZE COMMENT 4d2df61acb62 2 days ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "\"/us 0 B 9bde8bca4a09 2 days ago /bin/sh -c #(nop) EXPOSE 8080/tcp 0 B b64b9a3c9072 2 days ago /bin/sh -c #(nop) ADD dir:b736234a7bf1871f746 44.68 MB 7ba740e64ec0 2 days ago /bin/sh -c #(nop) MAINTAINER 979477675@qq.co 0 B 5e402de638b8 10 days ago /bin/sh -c #(nop) CMD ["catalina.sh" "run"] 0 B <missing> 10 days ago /bin/sh -c #(nop) EXPOSE 8080/tcp 0 B <missing> 10 days ago /bin/sh -c set -e && nativeLines="$(catalina 0 B <missing> 10 days ago /bin/sh -c set -eux; success=; for url in 17.78 MB <missing> 10 days ago /bin/sh -c #(nop) ENV TOMCAT_ASC_URLS=https: 0 B <missing> 10 days ago /bin/sh -c #(nop) ENV TOMCAT_TGZ_URLS=https: 0 B <missing> 10 days ago /bin/sh -c #(nop) ENV TOMCAT_SHA1=9e26ba61c5 0 B <missing> 10 days ago /bin/sh -c #(nop) ENV TOMCAT_VERSION=8.5.24 0 B <missing> 10 days ago /bin/sh -c #(nop) ENV TOMCAT_MAJOR=8 0 B <missing> 10 days ago /bin/sh -c set -ex; for key in $GPG_KEYS; do 121.5 kB <missing> 10 days ago /bin/sh -c #(nop) ENV GPG_KEYS=05AB331109497 0 B <missing> 10 days ago /bin/sh -c apt-get update && apt-get install 1.932 MB <missing> 10 days ago /bin/sh -c set -ex; currentVersion="$(dpkg-q 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV OPENSSL_VERSION=1.1.0f 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV LD_LIBRARY_PATH=/usr/l 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV TOMCAT_NATIVE_LIBDIR=/ 0 B <missing> 5 weeks ago /bin/sh -c #(nop) WORKDIR /usr/local/tomcat 0 B <missing> 5 weeks ago /bin/sh -c mkdir -p "$CATALINA_HOME" 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV PATH=/usr/local/tomcat 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV CATALINA_HOME=/usr/loc 0 B <missing> 5 weeks ago /bin/sh -c /var/lib/dpkg/info/ca-certificates 394.4 kB <missing> 5 weeks ago /bin/sh -c set -ex; if [ ! -d /usr/share/ma 403.5 MB <missing> 5 weeks ago /bin/sh -c #(nop) ENV CA_CERTIFICATES_JAVA_V 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV JAVA_DEBIAN_VERSION=8u 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV JAVA_VERSION=8u151 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV JAVA_HOME=/docker-java 0 B <missing> 5 weeks ago /bin/sh -c ln -svT "/usr/lib/jvm/java-8-openj 0 B <missing> 5 weeks ago /bin/sh -c { echo '#!/bin/sh'; echo 'set 87 B <missing> 5 weeks ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0 B <missing> 5 weeks ago /bin/sh -c apt-get update && apt-get install 2.048 MB <missing> 5 weeks ago /bin/sh -c set -ex; if ! command -v gpg > /d 7.801 MB <missing> 5 weeks ago /bin/sh -c apt-get update && apt-get install 23.82 MB <missing> 5 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0 B <missing> 5 weeks ago /bin/sh -c #(nop) ADD file:eb2519421c9794ccc9 100.1 MB [root@node1 tmp]#
将镜像保存 -o输出到文件 [root@node1 tmp]# docker save -o liwen.tar.gz 192.168.1.5:5000/tomcat:init [root@node1 tmp]# ll 总用量 563216 -rw------- 1 root root 576721408 1月 21 20:06 liwen.tar.gz
从文件中导入一个镜像 -i加载tar文件 [root@node1 tmp]# docker load -i liwen.tar.gz Loaded image: 192.168.1.5:5000/tomcat:init [root@node1 tmp]#
查看一个运行的容器的进程 [root@node1 tmp]# docker top b89a35fd7721 UID PID PPID C STIME TTY TIME CMD root 18426 18409 0 20:04 pts/1 00:00:00 /bin/sh -c "/usr/local/tomcat/bin/catalina.sh" "run" root 18459 18426 49 20:04 pts/1 00:02:03 /docker-java-home/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start [root@node1 tmp]#
给一个镜像打个新的标签
docker tag 新名字 源镜像名字
http://blog.chinaunix.net/uid-10915175-id-4443127.html
Welcome to visit