Docker常见命令整理汇总(包括镜像命令、容器命令)
目录
- docker帮助命令大全—help
- 管理镜像命令—image
- 管理网络命令—network
- 管理容器命令—container
- 管理服务命令—service
- 管理Docker镜像清单和清单列表—manifest
- 管理节点命令—node
- 管理插件命令—plugin
- 管理卷命令—volume
- 管理Docker命令—system
- 管理Docker映像的信任—trust
- 登录docker仓库命令—login
- 登出docker仓库命令—logout
- 使用Dockerfile构建一个镜像—build
- 搜索命令—search
- 下载镜像命令—pull
- 上传命令—push
- 删除镜像命令—rmi
- 删除容器命令—rm
- 运行容器命令—run
- 启动容器—start
- 重启容器命令—restart
- 停止运行容器命令—stop
- 标签命令—tag
- 获取元数据命令—inspect
- 显示容器资源使用情况—stats
- 容器重命名—rename
- 列出正在运行的容器命令—ps
- 显示日志命令—logs
- 显示整个系统的信息命令—info
- 显示系统版本—version
- 终止正在运行的容器—kill
- 进入正在运行的容器命令—exec
- 宿主机和容器之间拷贝文件—cp
- 根据容器的更改创建一个新镜像命令—commit
- 镜像保存为tar包命令—save
- 显示容器的运行进程—top
- 检查容器文件系统中文件或目录的更改—diff
- 显示镜像的历史信息—history
- 总结
docker帮助命令大全—help
命令帮助文档:Reference documentation | Docker Documentation
使用docker --help 帮助命令查看docker命令大全。
管理镜像命令—image
[root@docker ~]# docker image --help Usage: docker image COMMAND Manage images Commands: build Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE Run 'docker image COMMAND --help' for more information on a command.
查看镜像列表
[root@docker ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE composetest_web latest 9042ed0cbfa0 3 weeks ago 185MB xybdiy/tomcat 1.0 919be09704a3 3 weeks ago 759MB tomcat latest fb5657adc892 3 months ago 680MB wordpress latest c3c92cc3dcb1 3 months ago 616MB mysql 5.7 c20987f18b13 3 months ago 448MB redis alpine 3900abf41552 4 months ago 32.4MB python 3.7-alpine a1034fd13493 4 months ago 41.8MB redis 5.0.9-alpine3.11 3661c84ee9d0 24 months ago 29.8MB
查看某个镜像的具体信息
[root@docker ~]# docker image inspect a1034fd13493 [ { "Id": "sha256:a1034fd13493569ef2975c7c8c3bdd8aecee43aa2a9f102a24380b9cb724535b", "RepoTags": [ "python:3.7-alpine" ], "RepoDigests": [ "python@sha256:d64e0124674d64e78cc9d7378a1130499ced66a7a00db0521d0120a2e88ac9e4" ], "Parent": "", "Comment": "", "Created": "2021-11-30T03:49:39.993478495Z", "Container": "20e9649827ee5bdbd14de5ee48c24f4066c4130a87e6b2a77ed3310735573ddf", "ContainerConfig": { "Hostname": "20e9649827ee", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LANG=C.UTF-8", "GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D", "PYTHON_VERSION=3.7.12", "PYTHON_PIP_VERSION=21.2.4", "PYTHON_SETUPTOOLS_VERSION=57.5.0", "PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/3cb8888cc2869620f57d5d2da64da38f516078c7/public/get-pip.py", "PYTHON_GET_PIP_SHA256=c518250e91a70d7b20cceb15272209a4ded2a0c263ae5776f129e0d9b5674309" ], "Cmd": [ "/bin/sh", "-c", "#(nop) ", "CMD [\"python3\"]" ], "Image": "sha256:3544d8593ab7179c1becb3438d0bc7aa13c29c129631ed4c7459e11ec4a649da", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "DockerVersion": "20.10.7", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LANG=C.UTF-8", "GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D", "PYTHON_VERSION=3.7.12", "PYTHON_PIP_VERSION=21.2.4", "PYTHON_SETUPTOOLS_VERSION=57.5.0", "PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/3cb8888cc2869620f57d5d2da64da38f516078c7/public/get-pip.py", "PYTHON_GET_PIP_SHA256=c518250e91a70d7b20cceb15272209a4ded2a0c263ae5776f129e0d9b5674309" ], "Cmd": [ "python3" ], "Image": "sha256:3544d8593ab7179c1becb3438d0bc7aa13c29c129631ed4c7459e11ec4a649da", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 41825431, "VirtualSize": 41825431, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/7cf6e953229ea842d0bb8226b61332d3f15a7717d2076574d4300b9b8528251f/diff:/var/lib/docker/overlay2/40baea44309d169c8bb7ef1059e829b866fdb6c399646a0bf407229a1c0edbda/diff:/var/lib/docker/overlay2/0c1ab0a3a5380aed21110ad6fb5f884ff7823749f85114dd94dc43aab84585e6/diff:/var/lib/docker/overlay2/bebed63a08d4601f7f426801ff35f75afc1b9e8e9b74bfa08ed7f1986a2ea45d/diff", "MergedDir": "/var/lib/docker/overlay2/3ed0c36758ca879d553f296dd0d6447788db8715424acad066c739347c035411/merged", "UpperDir": "/var/lib/docker/overlay2/3ed0c36758ca879d553f296dd0d6447788db8715424acad066c739347c035411/diff", "WorkDir": "/var/lib/docker/overlay2/3ed0c36758ca879d553f296dd0d6447788db8715424acad066c739347c035411/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:8d3ac3489996423f53d6087c81180006263b79f206d3fdec9e66f0e27ceb8759", "sha256:1965cfbef2abbbc503a96e5dfd4db0baf850d58849a1d897c51c63e8a8bc71f1", "sha256:f16bf26b9fc19a90a93c3711e47a0d7c708ff912453f40db1ae1b1f9572d3426", "sha256:71d5256b1c5f0a51f494a60ff3719b37665ec4b8d848ce25dffe6606fb6ccf81", "sha256:741466cf7949b2c9be31f278f9658e14582fd400b6f8c03ca71193827cf747dd" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ]
管理网络命令—network
[root@docker ~]# docker network --help Usage: docker network COMMAND Manage networks Commands: connect Connect a container to a network #将容器连接到网络中 create Create a network #创建一个网络 disconnect Disconnect a container from a network #断开一个容器与网络的连接 inspect Display detailed information on one or more networks #显示一个或多个网络的详细信息 ls List networks # 网络列表 prune Remove all unused networks #移除所有未使用的网络 rm Remove one or more networks #移除一个或多个网络 Run 'docker network COMMAND --help' for more information on a command.
查看网络
[root@docker ~]# docker network ls NETWORK ID NAME DRIVER SCOPE fd76b35fdcdf bridge bridge local 6122e04c63b8 composetest_default bridge local 2fff17891e10 host host local 7aa928301028 mynet bridge local e09cdd0344b3 none null local 6e65d674deba redis bridge local 531566df42e7 xybdiy_workpress_default bridge local [root@docker ~]#
查看某个网络的具体参数信息
[root@docker ~]# docker network inspect fd76b35fdcdf [ { "Name": "bridge", "Id": "fd76b35fdcdf768530bb51f6de0cfeb9cc2a0cc1d4e61955f030324894025023", "Created": "2022-04-16T15:56:56.85375897+08:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": {}, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ]
管理容器命令—container
[root@docker ~]# docker container --help Usage: docker container COMMAND Manage containers Commands: attach Attach local standard input, output, and error streams to a running container 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 exec Run a command in a running container export Export a container's filesystem as a tar archive inspect Display detailed information on one or more containers kill Kill one or more running containers logs Fetch the logs of a container ls List containers pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container prune Remove all stopped containers rename Rename a container restart Restart one or more containers rm Remove one or more containers run Run a command in a new container 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 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 wait Block until one or more containers stop, then print their exit codes Run 'docker container COMMAND --help' for more information on a command.
管理服务命令—service
[root@docker ~]# docker service --help Usage: docker service COMMAND Manage services Commands: create Create a new service inspect Display detailed information on one or more services logs Fetch the logs of a service or task ls List services ps List the tasks of one or more services rm Remove one or more services rollback Revert changes to a service's configuration scale Scale one or multiple replicated services update Update a service Run 'docker service COMMAND --help' for more information on a command. [root@docker ~]#
管理Docker镜像清单和清单列表—manifest
[root@docker ~]# docker manifest --help Usage: docker manifest COMMAND The **docker manifest** command has subcommands for managing image manifests and manifest lists. A manifest list allows you to use one name to refer to the same image built for multiple architectures. To see help for a subcommand, use: docker manifest CMD --help For full details on using docker manifest lists, see the registry v2 specification. EXPERIMENTAL: docker manifest is an experimental feature. Experimental features provide early access to product functionality. These features may change between releases without warning, or can be removed from a future release. Learn more about experimental features in our documentation: https://docs.docker.com/go/experimental/ Commands: annotate Add additional information to a local image manifest create Create a local manifest list for annotating and pushing to a registry inspect Display an image manifest, or manifest list push Push a manifest list to a repository rm Delete one or more manifest lists from local storage Run 'docker manifest COMMAND --help' for more information on a command.
管理节点命令—node
[root@docker ~]# docker node --help Usage: docker node COMMAND Manage Swarm nodes Commands: demote Demote one or more nodes from manager in the swarm inspect Display detailed information on one or more nodes ls List nodes in the swarm promote Promote one or more nodes to manager in the swarm ps List tasks running on one or more nodes, defaults to current node rm Remove one or more nodes from the swarm update Update a node Run 'docker node COMMAND --help' for more information on a command.
管理插件命令—plugin
[root@docker ~]# docker plugin --help Usage: docker plugin COMMAND Manage plugins Commands: create Create a plugin from a rootfs and configuration. Plugin data directory must contain config.json and rootfs directory. disable Disable a plugin enable Enable a plugin inspect Display detailed information on one or more plugins install Install a plugin ls List plugins push Push a plugin to a registry rm Remove one or more plugins set Change settings for a plugin upgrade Upgrade an existing plugin Run 'docker plugin COMMAND --help' for more information on a command.
管理卷命令—volume
[root@docker ~]# docker volume --help Usage: docker volume COMMAND Manage volumes Commands: create Create a volume inspect Display detailed information on one or more volumes ls List volumes prune Remove all unused local volumes rm Remove one or more volumes Run 'docker volume COMMAND --help' for more information on a command.
查看卷列表
[root@docker ~]# docker volume ls DRIVER VOLUME NAME local 620ad95e4c51ab149e9d7dbc7e8e6133649836e96c53e8eca7d1d7b29c43ab9f local 7237b92108c059d26020e27c85f48856f4dacbd3d268d48af2b600a859ae706a local 21878df70d6fbf66367dd3af286aba6660e7b4b859e6b580567e50f907792456 local 5927434c30ba651b152ff660d58828e8e565559951445ba3387f1ec9b26f157d local cfde92442be6bb35c8b0d7d6dc7f9a3a026a1ff39c887a07b20443df10c50edc local fad8a6ebf7c93f6d97229ed2066ab9e22423176e4f7c7bf452fe3cf95bfe1327 local ff9a1d3a9db6329cb1f19c6c1a203a9371197165cd2654e9d92a5b196ade988b local ffc429344b4736efac5fb51f5f91639cf984a2eb86122001d831eb3c0f364a2c local juming-nginx local xybdiy_workpress_db_data local xybdiy_workpress_wordpress_data
管理Docker命令—system
使用帮助命令查看system命令的具体参数
[root@docker ~]# docker system --help Usage: docker system COMMAND Manage Docker Commands: df Show docker disk usage events Get real time events from the server info Display system-wide information prune Remove unused data Run 'docker system COMMAND --help' for more information on a command.
显示docker的磁盘使用情况
[root@docker ~]# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 8 0 2.745GB 2.745GB (100%) Containers 0 0 0B 0B Local Volumes 11 0 284.3MB 284.3MB (100%) Build Cache 0 0 0B 0B
从服务器获取实时事件
[root@docker ~]# docker system events 2022-04-16T16:51:36.016722358+08:00 image pull wordpress:latest (name=wordpress)
显示整个系统的信息
[root@docker ~]# docker system info Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Docker Buildx (Docker Inc., v0.8.0-docker) scan: Docker Scan (Docker Inc., v0.17.0) Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 16 Server Version: 20.10.13 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc runc version: v1.0.3-0-gf46b6ba init version: de40ad0 Security Options: seccomp Profile: default Kernel Version: 3.10.0-1160.59.1.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 3.84GiB Name: docker ID: CFVH:DD5W:4Q47:PBFJ:UK4Y:KZCL:263B:IESI:2IUJ:VMSF:TK27:XYMQ Docker Root Dir: /var/lib/docker Debug Mode: false Username: xybdiy Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://w2kavmmf.mirror.aliyuncs.com/ Live Restore Enabled: false
管理Docker映像的信任—trust
[root@docker ~]# docker trust --help Usage: docker trust COMMAND Manage trust on Docker images Management Commands: key Manage keys for signing Docker images signer Manage entities who can sign Docker images Commands: inspect Return low-level information about keys and signatures revoke Remove trust for an image sign Sign an image Run 'docker trust COMMAND --help' for more information on a command.
登录docker仓库命令—login
[root@docker ~]# docker login --help Usage: docker login [OPTIONS] [SERVER] Log in to a Docker registry. If no server is specified, the default is defined by the daemon. Options: -p, --password string Password --password-stdin Take the password from stdin -u, --username string Username
登出docker仓库命令—logout
[root@docker ~]# docker logout --help Usage: docker logout [SERVER] Log out from a Docker registry. If no server is specified, the default is defined by the daemon.
使用Dockerfile构建一个镜像—build
[root@docker ~]# docker build --help Usage: docker build [OPTIONS] PATH | URL | - Build an image from a Dockerfile Options: --add-host list Add a custom host-to-IP mapping (host:ip) --build-arg list Set build-time variables --cache-from strings Images to consider as cache sources --cgroup-parent string Optional parent cgroup for the container --compress Compress the build context using gzip --cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota -c, --cpu-shares int CPU shares (relative weight) --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) --disable-content-trust Skip image verification (default true) -f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile') --force-rm Always remove intermediate containers --iidfile string Write the image ID to the file --isolation string Container isolation technology --label list Set metadata for an image -m, --memory bytes Memory limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --network string Set the networking mode for the RUN instructions during build (default "default") --no-cache Do not use cache when building the image --pull Always attempt to pull a newer version of the image -q, --quiet Suppress the build output and print image ID on success --rm Remove intermediate containers after a successful build (default true) --security-opt strings Security options --shm-size bytes Size of /dev/shm -t, --tag list Name and optionally a tag in the 'name:tag' format --target string Set the target build stage to build. --ulimit ulimit Ulimit options (default [])
搜索命令—search
[root@docker ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 12419 [OK] mariadb MariaDB Server is a high performing open sou… 4784 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 918 [OK] percona Percona Server is a fork of the MySQL relati… 575 [OK] phpmyadmin phpMyAdmin - A web interface for MySQL and M… 505 [OK] mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 93 centos/mysql-57-centos7 MySQL 5.7 SQL database server 92 bitnami/mysql Bitnami MySQL Docker Image 69 [OK] ubuntu/mysql MySQL open source fast, stable, multi-thread… 29 circleci/mysql MySQL is a widely used, open-source relation… 25 mysql/mysql-router MySQL Router provides transparent routing be… 23 centos/mysql-56-centos7 MySQL 5.6 SQL database server 22 google/mysql MySQL server for Google Compute Engine 21 [OK] vmware/harbor-db Mysql container for Harbor 10 bitnami/mysqld-exporter 3 mysqlboy/docker-mydumper docker-mydumper containerizes MySQL logical … 3 mysqlboy/mydumper mydumper for mysql logcial backups 3 ibmcom/mysql-s390x Docker image for mysql-s390x 2 mysql/mysql-operator MySQL Operator for Kubernetes 0 cimg/mysql 0 mysqlboy/elasticsearch 0 mysqleatmydata/mysql-eatmydata 0 ibmcom/tidb-ppc64le TiDB is a distributed NewSQL database compat… 0 mysql/ndb-operator MySQL NDB Operator for Kubernetes 0 mirantis/mysql 0
下载镜像命令—pull
[root@docker ~]# docker pull --help Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] Pull an image or a repository from a registry Options: -a, --all-tags Download all tagged images in the repository --disable-content-trust Skip image verification (default true) --platform string Set platform if server is multi-platform capable -q, --quiet Suppress verbose output [root@docker ~]#
下载MySQL最新镜像文件
# 下载镜像 docker pull 镜像名[:tag] [root@docker ~]# docker pull mysql Using default tag: latest #如果不写 tag,默认是latest latest: Pulling from library/mysql 72a69066d2fe: Already exists #分层下载,已存在的文件可以共享 93619dbc5b36: Already exists 99da31dd6142: Already exists 626033c43d70: Already exists 37d5d7efb64e: Already exists ac563158d721: Already exists d2ba16033dad: Already exists 688ba7d5c01a: Pull complete 00e060b6d11d: Pull complete 1c04857f594f: Pull complete 4d7cfa90e6ea: Pull complete e0431212d27d: Pull complete Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 Status: Downloaded newer image for mysql:latest docker.io/library/mysql:latest 下载指定版本的镜像文件 [root@docker ~]# docker pull mysql:5.7 5.7: Pulling from library/mysql Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94 Status: Image is up to date for mysql:5.7 docker.io/library/mysql:5.7
上传命令—push
[root@docker ~]# docker push --help Usage: docker push [OPTIONS] NAME[:TAG] Push an image or a repository to a registry Options: -a, --all-tags Push all tagged images in the repository --disable-content-trust Skip image signing (default true) -q, --quiet Suppress verbose output
删除镜像命令—rmi
[root@docker ~]# docker rmi --help Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] Remove one or more images Options: -f, --force Force removal of the image --no-prune Do not delete untagged parents
删除镜像操作
# 查询镜像,使用IMAGE ID删除 [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 3218b38490ce 3 months ago 516MB [root@docker ~]# docker rmi 3218b38490ce Untagged: mysql:latest Untagged: mysql@sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 Deleted: sha256:3218b38490cec8d31976a40b92e09d61377359eab878db49f025e5d464367f3b Deleted: sha256:aa81ca46575069829fe1b3c654d9e8feb43b4373932159fe2cad1ac13524a2f5 Deleted: sha256:0558823b9fbe967ea6d7174999be3cc9250b3423036370dc1a6888168cbd224d Deleted: sha256:a46013db1d31231a0e1bac7eeda5ad4786dea0b1773927b45f92ea352a6d7ff9 Deleted: sha256:af161a47bb22852e9e3caf39f1dcd590b64bb8fae54315f9c2e7dc35b025e4e3 Deleted: sha256:feff1495e6982a7e91edc59b96ea74fd80e03674d92c7ec8a502b417268822ff # 删除多个容器 docker rmi 容器id 容器id 容器id # 删除所有镜像 [root@docker ~]# docker rmi -f $(docker images -aq)
删除容器命令—rm
[root@docker ~]# docker rm --help Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] Remove one or more containers Options: -f, --force Force the removal of a running container (uses SIGKILL) -l, --link Remove the specified link -v, --volumes Remove anonymous volumes associated with the container
运行容器命令—run
[root@docker ~]# docker run --help Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container Options: --add-host list Add a custom host-to-IP mapping (host:ip) -a, --attach list Attach to STDIN, STDOUT or STDERR --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --blkio-weight-device list Block IO weight (relative device weight) (default []) --cap-add list Add Linux capabilities --cap-drop list Drop Linux capabilities --cgroup-parent string Optional parent cgroup for the container --cgroupns string Cgroup namespace to use (host|private) 'host': Run the container in the Docker host's cgroup namespace 'private': Run the container in its own private cgroup namespace '': Use the cgroup namespace as configured by the default-cgroupns-mode option on the daemon (default) --cidfile string Write the container ID to the file --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit CPU real-time period in microseconds --cpu-rt-runtime int Limit CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) -d, --detach Run container in background and print container ID --detach-keys string Override the key sequence for detaching a container --device list Add a host device to the container --device-cgroup-rule list Add a rule to the cgroup allowed devices list --device-read-bps list Limit read rate (bytes per second) from a device (default []) --device-read-iops list Limit read rate (IO per second) from a device (default []) --device-write-bps list Limit write rate (bytes per second) to a device (default []) --device-write-iops list Limit write rate (IO per second) to a device (default []) --disable-content-trust Skip image verification (default true) --dns list Set custom DNS servers --dns-option list Set DNS options --dns-search list Set custom DNS search domains --domainname string Container NIS domain name --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --expose list Expose a port or a range of ports --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs) --group-add list Add additional groups to join --health-cmd string Command to run to check health --health-interval duration Time between running the check (ms|s|m|h) (default 0s) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s) --help Print usage -h, --hostname string Container host name --init Run an init inside the container that forwards signals and reaps processes -i, --interactive Keep STDIN open even if not attached --ip string IPv4 address (e.g., 172.30.100.104) --ip6 string IPv6 address (e.g., 2001:db8::33) --ipc string IPC mode to use --isolation string Container isolation technology --kernel-memory bytes Kernel memory limit -l, --label list Set meta data on a container --label-file list Read in a line delimited file of labels --link list Add link to another container --link-local-ip list Container IPv4/IPv6 link-local addresses --log-driver string Logging driver for the container --log-opt list Log driver options --mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33) -m, --memory bytes Memory limit --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) --mount mount Attach a filesystem mount to the container --name string Assign a name to the container --network network Connect a container to a network --network-alias list Add network-scoped alias for the container --no-healthcheck Disable any container-specified HEALTHCHECK --oom-kill-disable Disable OOM Killer --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) --pid string PID namespace to use --pids-limit int Tune container pids limit (set -1 for unlimited) --platform string Set platform if server is multi-platform capable --privileged Give extended privileges to this container -p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --pull string Pull image before running ("always"|"missing"|"never") (default "missing") --read-only Mount the container's root filesystem as read only --restart string Restart policy to apply when a container exits (default "no") --rm Automatically remove the container when it exits --runtime string Runtime to use for this container --security-opt list Security Options --shm-size bytes Size of /dev/shm --sig-proxy Proxy received signals to the process (default true) --stop-signal string Signal to stop a container (default "SIGTERM") --stop-timeout int Timeout (in seconds) to stop a container --storage-opt list Storage driver options for the container --sysctl map Sysctl options (default map[]) --tmpfs list Mount a tmpfs directory -t, --tty Allocate a pseudo-TTY --ulimit ulimit Ulimit options (default []) -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) --userns string User namespace to use --uts string UTS namespace to use -v, --volume list Bind mount a volume --volume-driver string Optional volume driver for the container --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container
启动容器—start
[root@docker ~]# docker start --help Usage: docker start [OPTIONS] CONTAINER [CONTAINER...] Start one or more stopped containers Options: -a, --attach Attach STDOUT/STDERR and forward signals --detach-keys string Override the key sequence for detaching a container -i, --interactive Attach container's STDIN
重启容器命令—restart
[root@docker ~]# docker restart --help Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] Restart one or more containers Options: -t, --time int Seconds to wait for stop before killing the container (default 10)
停止运行容器命令—stop
[root@docker ~]# docker stop --help Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] Stop one or more running containers Options: -t, --time int Seconds to wait for stop before killing it (default 10)
标签命令—tag
[root@docker ~]# docker tag --help Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
获取元数据命令—inspect
[root@docker ~]# docker inspect --help Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...] Return low-level information on Docker objects Options: -f, --format string Format the output using the given Go template -s, --size Display total file sizes if the type is container --type string Return JSON for specified type
显示容器资源使用情况—stats
[root@docker ~]# docker stats --help Usage: docker stats [OPTIONS] [CONTAINER...] Display a live stream of container(s) resource usage statistics Options: -a, --all Show all containers (default shows just running) --format string Pretty-print images using a Go template --no-stream Disable streaming stats and only pull the first result --no-trunc Do not truncate output
容器重命名—rename
[root@docker ~]# docker rename --help Usage: docker rename CONTAINER NEW_NAME Rename a container
列出正在运行的容器命令—ps
[root@docker ~]# docker ps --help Usage: docker ps [OPTIONS] List containers Options: -a, --all Show all containers (default shows just running) -f, --filter filter Filter output based on conditions provided --format string Pretty-print containers using a Go template -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) --no-trunc Don't truncate output -q, --quiet Only display container IDs -s, --size Display total file sizes
显示日志命令—logs
[root@docker ~]# docker logs --help Usage: docker logs [OPTIONS] CONTAINER Fetch the logs of a container Options: --details Show extra details provided to logs -f, --follow Follow log output --since string Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes) -n, --tail string Number of lines to show from the end of the logs (default "all") -t, --timestamps Show timestamps --until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
显示整个系统的信息命令—info
[root@docker ~]# docker info --help Usage: docker info [OPTIONS] Display system-wide information Options: -f, --format string Format the output using the given Go template
显示系统版本—version
[root@docker ~]# docker version --help Usage: docker version [OPTIONS] Show the Docker version information Options: -f, --format string Format the output using the given Go template --kubeconfig string Kubernetes config file
终止正在运行的容器—kill
[root@docker ~]# docker kill --help Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] Kill one or more running containers Options: -s, --signal string Signal to send to the container (default "KILL")
进入正在运行的容器命令—exec
[root@docker ~]# docker exec --help Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container Options: -d, --detach Detached mode: run command in the background --detach-keys string Override the key sequence for detaching a container -e, --env list Set environment variables --env-file list Read in a file of environment variables -i, --interactive Keep STDIN open even if not attached --privileged Give extended privileges to the command -t, --tty Allocate a pseudo-TTY -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) -w, --workdir string Working directory inside the container
宿主机和容器之间拷贝文件—cp
[root@docker ~]# docker cp --help Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH Copy files/folders between a container and the local filesystem Use '-' as the source to read a tar archive from stdin and extract it to a directory destination in a container. Use '-' as the destination to stream a tar archive of a container source to stdout. Options: -a, --archive Archive mode (copy all uid/gid information) -L, --follow-link Always follow symbol link in SRC_PATH
根据容器的更改创建一个新镜像命令—commit
[root@docker ~]# docker commit --help Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Create a new image from a container's changes Options: -a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>") -c, --change list Apply Dockerfile instruction to the created image -m, --message string Commit message -p, --pause Pause container during commit (default true)
镜像保存为tar包命令—save
[root@docker ~]# docker save --help Usage: docker save [OPTIONS] IMAGE [IMAGE...] Save one or more images to a tar archive (streamed to STDOUT by default) Options: -o, --output string Write to a file, instead of STDOUT
显示容器的运行进程—top
[root@docker ~]# docker top --help Usage: docker top CONTAINER [ps OPTIONS] Display the running processes of a container
检查容器文件系统中文件或目录的更改—diff
[root@docker ~]# docker diff --help Usage: docker diff CONTAINER Inspect changes to files or directories on a container's filesystem
显示镜像的历史信息—history
[root@docker ~]# docker history --help Usage: docker history [OPTIONS] IMAGE Show the history of an image Options: --format string Pretty-print images using a Go template -H, --human Print sizes and dates in human readable format (default true) --no-trunc Don't truncate output -q, --quiet Only show image IDs
创建一个新的容器命令—create
[root@docker ~]# docker create --help Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...] Create a new container Options: --add-host list Add a custom host-to-IP mapping (host:ip) -a, --attach list Attach to STDIN, STDOUT or STDERR --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --blkio-weight-device list Block IO weight (relative device weight) (default []) --cap-add list Add Linux capabilities --cap-drop list Drop Linux capabilities --cgroup-parent string Optional parent cgroup for the container --cgroupns string Cgroup namespace to use (host|private) 'host': Run the container in the Docker host's cgroup namespace 'private': Run the container in its own private cgroup namespace '': Use the cgroup namespace as configured by the default-cgroupns-mode option on the daemon (default) --cidfile string Write the container ID to the file --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit CPU real-time period in microseconds --cpu-rt-runtime int Limit CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) --device list Add a host device to the container --device-cgroup-rule list Add a rule to the cgroup allowed devices list --device-read-bps list Limit read rate (bytes per second) from a device (default []) --device-read-iops list Limit read rate (IO per second) from a device (default []) --device-write-bps list Limit write rate (bytes per second) to a device (default []) --device-write-iops list Limit write rate (IO per second) to a device (default []) --disable-content-trust Skip image verification (default true) --dns list Set custom DNS servers --dns-option list Set DNS options --dns-search list Set custom DNS search domains --domainname string Container NIS domain name --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --expose list Expose a port or a range of ports --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs) --group-add list Add additional groups to join --health-cmd string Command to run to check health --health-interval duration Time between running the check (ms|s|m|h) (default 0s) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s) --help Print usage -h, --hostname string Container host name --init Run an init inside the container that forwards signals and reaps processes -i, --interactive Keep STDIN open even if not attached --ip string IPv4 address (e.g., 172.30.100.104) --ip6 string IPv6 address (e.g., 2001:db8::33) --ipc string IPC mode to use --isolation string Container isolation technology --kernel-memory bytes Kernel memory limit -l, --label list Set meta data on a container --label-file list Read in a line delimited file of labels --link list Add link to another container --link-local-ip list Container IPv4/IPv6 link-local addresses --log-driver string Logging driver for the container --log-opt list Log driver options --mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33) -m, --memory bytes Memory limit --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) --mount mount Attach a filesystem mount to the container --name string Assign a name to the container --network network Connect a container to a network --network-alias list Add network-scoped alias for the container --no-healthcheck Disable any container-specified HEALTHCHECK --oom-kill-disable Disable OOM Killer --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) --pid string PID namespace to use --pids-limit int Tune container pids limit (set -1 for unlimited) --platform string Set platform if server is multi-platform capable --privileged Give extended privileges to this container -p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --pull string Pull image before creating ("always"|"missing"|"never") (default "missing") --read-only Mount the container's root filesystem as read only --restart string Restart policy to apply when a container exits (default "no") --rm Automatically remove the container when it exits --runtime string Runtime to use for this container --security-opt list Security Options --shm-size bytes Size of /dev/shm --stop-signal string Signal to stop a container (default "SIGTERM") --stop-timeout int Timeout (in seconds) to stop a container --storage-opt list Storage driver options for the container --sysctl map Sysctl options (default map[]) --tmpfs list Mount a tmpfs directory -t, --tty Allocate a pseudo-TTY --ulimit ulimit Ulimit options (default []) -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) --userns string User namespace to use --uts string UTS namespace to use -v, --volume list Bind mount a volume --volume-driver string Optional volume driver for the container --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container
总结
到此这篇关于Docker常见命令整理汇总的文章就介绍到这了,更多相关Docker常见命令内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
赞 (0)