【Docker】Docker常见命令汇总(上)

简介: 【Docker】Docker常见命令汇总

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


相关文章
|
2月前
|
监控 Docker 容器
Docker 启动命令里 --cgroupns host 是什么作用?
【8月更文挑战第19天】Docker 启动命令里 --cgroupns host 是什么作用?
105 1
|
7天前
|
Linux Docker 容器
linux之docker命令
linux之docker命令
|
1月前
|
应用服务中间件 Shell nginx
Docker容器操作基础命令
关于Docker容器操作基础命令的教程,涵盖了从启动、查看、删除容器到端口映射和容器信息获取的一系列常用命令及其使用方法。
63 14
|
27天前
|
存储 Docker 容器
docker save命令和load命令
docker save命令和load命令
|
2月前
|
JSON JavaScript 开发者
Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
【8月更文挑战第7天】Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
|
6天前
|
Ubuntu Shell Docker
docker使用什么命令让时间恢复正确啊
docker使用什么命令让时间恢复正确啊
|
6天前
|
Docker 容器
7-13|docker build -t image-name:tag path/to/Dockerfile 这个命令具体什么意思
7-13|docker build -t image-name:tag path/to/Dockerfile 这个命令具体什么意思
|
2月前
|
Docker 容器
Docker Kill/Pause/Unpause命令详细使用指南
总之,`docker kill`、`docker pause`和 `docker unpause`命令是对容器执行快速状态控制操作的有力工具。使用这些命令可以帮助您更好地管理容器,并在需要时快速响应异常情况。在操作过程中,应当谨慎使用 `docker kill`,因为它将导致容器立即停止,有可能导致数据丢失或文件系统损坏。在可能的情况下,先尝试使用 `docker stop`命令以正常方式停止容器。
27 2
|
2月前
|
负载均衡 调度 Docker
|
2月前
|
存储 Docker 容器
在Docker中,容器退出后,通过docker ps命令查看不到,数据会丢失么?
在Docker中,容器退出后,通过docker ps命令查看不到,数据会丢失么?
下一篇
无影云桌面