ToB企服应用市场:ToB评测及商务社交产业平台

标题: 云盘算Docker实验陈诉 实验一1.1 Docker下令的使用 [打印本页]

作者: 南七星之家    时间: 2024-6-15 01:04
标题: 云盘算Docker实验陈诉 实验一1.1 Docker下令的使用
docker官方下令文档
菜鸟dockerm下令大全
仅仅是个人的课程实验陈诉,学习Docker还请参考其他更专业的文档。
云盘算实验陈诉

专 业: 数据科学与大数据技能 班 级: 数据Q201  
实验1:Docker镜像容器下令测试
实验设备:
OS: Ubuntu/Centos
应用软件:Docker
实验目的:
1.把握部分镜像与容器下令
2.Docker注册中央的使用与操作
实验内容:
1、测试Docker镜像与容器下令
2、测试Docker注册中央的用法
实验陈诉要求:
以截图的情势显示代码运行结果、验证操作是否成功。
实验结果:

  
1.1、Docker的常用下令

资助下令:

docker version #显示docker的版本信息

  1. [root@lh2022 Docker]# docker -v
  2. Docker version 24.0.7, build afdd53b
  3. [root@lh2022 Docker]# docker version
  4. Client: Docker Engine - Community
  5. Version:           24.0.7
  6. API version:       1.43
  7. Go version:        go1.20.10
  8. Git commit:        afdd53b
  9. Built:             Thu Oct 26 09:11:35 2023
  10. OS/Arch:           linux/amd64
  11. Context:           default
  12. Server: Docker Engine - Community
  13. Engine:
  14.   Version:          24.0.7
  15.   API version:      1.43 (minimum version 1.12)
  16.   Go version:       go1.20.10
  17.   Git commit:       311b9ff
  18.   Built:            Thu Oct 26 09:10:36 2023
  19.   OS/Arch:          linux/amd64
  20.   Experimental:     false
  21. containerd:
  22.   Version:          1.6.24
  23.   GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
  24. runc:
  25.   Version:          1.1.9
  26.   GitCommit:        v1.1.9-0-gccaecfc
  27. docker-init:
  28.   Version:          0.19.0
  29.   GitCommit:        de40ad0
复制代码
docker info #显示docker的系统信息,包罗镜像和容器的数量

  1. [root@lh2022 Docker]# docker info
  2. Client: Docker Engine - Community
  3. Version:    24.0.7
  4. Context:    default
  5. Debug Mode: false
  6. Plugins:
  7.   buildx: Docker Buildx (Docker Inc.)
  8.     Version:  v0.11.2
  9.     Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  10.   compose: Docker Compose (Docker Inc.)
  11.     Version:  v2.21.0
  12.     Path:     /usr/libexec/docker/cli-plugins/docker-compose
  13. Server:
  14. Containers: 0
  15.   Running: 0
  16.   Paused: 0
  17.   Stopped: 0
  18. Images: 0
  19. Server Version: 24.0.7
  20. Storage Driver: overlay2
  21.   Backing Filesystem: xfs
  22.   Supports d_type: true
  23.   Using metacopy: false
  24.   Native Overlay Diff: true
  25.   userxattr: false
  26. Logging Driver: json-file
  27. Cgroup Driver: cgroupfs
  28. Cgroup Version: 1
  29. Plugins:
  30.   Volume: local
  31.   Network: bridge host ipvlan macvlan null overlay
  32.   Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  33. Swarm: inactive
  34. Runtimes: io.containerd.runc.v2 runc
  35. Default Runtime: runc
  36. Init Binary: docker-init
  37. containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
  38. runc version: v1.1.9-0-gccaecfc
  39. init version: de40ad0
  40. Security Options:
  41.   seccomp
  42.    Profile: builtin
  43. Kernel Version: 3.10.0-693.el7.x86_64
  44. Operating System: CentOS Linux 7 (Core)
  45. OSType: linux
  46. Architecture: x86_64
  47. CPUs: 4
  48. Total Memory: 1.781GiB
  49. Name: lh2022
  50. ID: fb7e86a2-fd72-44f2-9033-6e476d82aa8e
  51. Docker Root Dir: /var/lib/docker
  52. Debug Mode: false
  53. Experimental: false
  54. Insecure Registries:
  55.   127.0.0.0/8
  56. Registry Mirrors:
  57.   https://d45q22s3.mirror.aliyuncs.com/
  58. Live Restore Enabled: false
复制代码
docker --help #万能下令,查阅下令详情

  1. [root@lh2022 Docker]# docker --help
  2. Usage:  docker [OPTIONS] COMMAND
  3. A self-sufficient runtime for containers
  4. Common Commands:
  5.   run         Create and run a new container from an image
  6.   exec        Execute a command in a running container
  7.   ps          List containers
  8.   build       Build an image from a Dockerfile
  9.   pull        Download an image from a registry
  10.   push        Upload an image to a registry
  11.   images      List images
  12.   login       Log in to a registry
  13.   logout      Log out from a registry
  14.   search      Search Docker Hub for images
  15.   version     Show the Docker version information
  16.   info        Display system-wide information
  17. Management Commands:
  18.   builder     Manage builds
  19.   buildx*     Docker Buildx (Docker Inc., v0.11.2)
  20.   compose*    Docker Compose (Docker Inc., v2.21.0)
  21.   container   Manage containers
  22.   context     Manage contexts
  23.   image       Manage images
  24.   manifest    Manage Docker image manifests and manifest lists
  25.   network     Manage networks
  26.   plugin      Manage plugins
  27.   system      Manage Docker
  28.   trust       Manage trust on Docker images
  29.   volume      Manage volumes
  30. Swarm Commands:
  31.   swarm       Manage Swarm
  32. Commands:
  33.   attach      Attach local standard input, output, and error streams to a running container
  34.   commit      Create a new image from a container's changes
  35.   cp          Copy files/folders between a container and the local filesystem
  36.   create      Create a new container
  37.   diff        Inspect changes to files or directories on a container's filesystem
  38.   events      Get real time events from the server
  39.   export      Export a container's filesystem as a tar archive
  40.   history     Show the history of an image
  41.   import      Import the contents from a tarball to create a filesystem image
  42.   inspect     Return low-level information on Docker objects
  43.   kill        Kill one or more running containers
  44.   load        Load an image from a tar archive or STDIN
  45.   logs        Fetch the logs of a container
  46.   pause       Pause all processes within one or more containers
  47.   port        List port mappings or a specific mapping for the container
  48.   rename      Rename a container
  49.   restart     Restart one or more containers
  50.   rm          Remove one or more containers
  51.   rmi         Remove one or more images
  52.   save        Save one or more images to a tar archive (streamed to STDOUT by default)
  53.   start       Start one or more stopped containers
  54.   stats       Display a live stream of container(s) resource usage statistics
  55.   stop        Stop one or more running containers
  56.   tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  57.   top         Display the running processes of a container
  58.   unpause     Unpause all processes within one or more containers
  59.   update      Update configuration of one or more containers
  60.   wait        Block until one or more containers stop, then print their exit codes
  61. Global Options:
  62.       --config string      Location of client config files (default "/root/.docker")
  63.   -c, --context string     Name of the context to use to connect to the daemon
  64.                            (overrides DOCKER_HOST env var and default context set with
  65.                            "docker context use")
  66.   -D, --debug              Enable debug mode
  67.   -H, --host list          Daemon socket to connect to
  68.   -l, --log-level string   Set the logging level ("debug", "info", "warn", "error",
  69.                            "fatal") (default "info")
  70.       --tls                Use TLS; implied by --tlsverify
  71.       --tlscacert string   Trust certs signed only by this CA (default
  72.                            "/root/.docker/ca.pem")
  73.       --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
  74.       --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
  75.       --tlsverify          Use TLS and verify the remote
  76.   -v, --version            Print version information and quit
  77. Run 'docker COMMAND --help' for more information on a command.
  78. For more help on how to use Docker, head to https://docs.docker.com/go/guides/
复制代码
docker详细下令–help # 检察docker下令资助文档

  1. [root@lh2022 Docker]# docker ps --help
  2. Usage:  docker ps [OPTIONS]
  3. List containers
  4. Aliases:
  5.   docker container ls, docker container list, docker container ps, docker ps
  6. Options:
  7.   -a, --all             Show all containers (default shows just running)
  8.   -f, --filter filter   Filter output based on conditions provided
  9.       --format string   Format output using a custom template:
  10.                         'table':            Print output in table format with column
  11.                         headers (default)
  12.                         'table TEMPLATE':   Print output in table format using the given
  13.                         Go template
  14.                         'json':             Print in JSON format
  15.                         'TEMPLATE':         Print output using the given Go template.
  16.                         Refer to https://docs.docker.com/go/formatting/ for more
  17.                         information about formatting output with templates
  18.   -n, --last int        Show n last created containers (includes all states) (default -1)
  19.   -l, --latest          Show the latest created container (includes all states)
  20.       --no-trunc        Don't truncate output
  21.   -q, --quiet           Only display container IDs
  22.   -s, --size            Display total file sizes
复制代码
镜像下令:

docker images [options] #检察所有本地镜像

  1. [root@lh2022 Docker]# docker images
  2. REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
  3. mysql         5.7       c20987f18b13   23 months ago   448MB
  4. mysql         latest    3218b38490ce   23 months ago   516MB
  5. hello-world   latest    feb5d9fea6a5   2 years ago     13.3kB
复制代码
各个选项说明:

用–help下令检察该下令的详细使用方法。
  1. [root@lh2022 Docker]# docker images --help
  2. Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]
  3. List images
  4. Aliases:
  5.   docker image ls, docker image list, docker images
  6. Options:
  7.   -a, --all             Show all images (default hides intermediate images)
  8.       --digests         Show digests
  9.   -f, --filter filter   Filter output based on conditions provided
  10.       --format string   Format output using a custom template:
  11.                         'table':            Print output in table format with column
  12.                         headers (default)
  13.                         'table TEMPLATE':   Print output in table format using the given
  14.                         Go template
  15.                         'json':             Print in JSON format
  16.                         'TEMPLATE':         Print output using the given Go template.
  17.                         Refer to https://docs.docker.com/go/formatting/ for more
  18.                         information about formatting output with templates
  19.       --no-trunc        Don't truncate output
  20.   -q, --quiet           Only show image IDs
复制代码
Options

-a, --all #列出所有的镜像
-q, --quite #只显示镜像的id

  1. [root@lh2022 Docker]# docker images -a
  2. REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
  3. mysql         5.7       c20987f18b13   23 months ago   448MB
  4. mysql         latest    3218b38490ce   23 months ago   516MB
  5. hello-world   latest    feb5d9fea6a5   2 years ago     13.3kB
  6. [root@lh2022 Docker]# docker images -q
  7. c20987f18b13
  8. 3218b38490ce
  9. feb5d9fea6a5
复制代码
docker search #搜刮镜像

docker search 镜像名(搜刮全部相干镜像)
  1. [root@lh2022 Docker]# docker search hello-world
  2. NAME                                       DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
  3. hello-world                                Hello World! (an example of minimal Dockeriz…   2137      [OK]      
  4. rancher/hello-world                        This container image is no longer maintained…   4                    
  5. okteto/hello-world                                                                          0                    
  6. tacc/hello-world                                                                            0                    
  7. armswdev/c-hello-world                     Simple hello-world C program on Alpine Linux…   0                    
复制代码
用 --help 下令检察该下令的详细使用方法。
  1. [root@lh2022 Docker]# docker search --help
  2. Usage:  docker search [OPTIONS] TERM
  3. Search Docker Hub for images
  4. Options:
  5.   -f, --filter filter   Filter output based on conditions provided
  6.       --format string   Pretty-print search using a Go template
  7.       --limit int       Max number of search results
  8.       --no-trunc        Don't truncate output
复制代码
docker search 镜像名 -f 过滤条件 #搜刮符合过滤条件的镜像 f=filter 即过滤器。

搜刮吗hello-world 镜像的 stats>=3000的镜像。
  1. [root@lh2022 Docker]# docker search hello-world --filter=STARS=3000
  2. NAME      DESCRIPTION   STARS     OFFICIAL   AUTOMATED
复制代码
搜刮stats>=2000的镜像。
  1. [root@lh2022 Docker]# docker search hello-world --filter=STARS=2000
  2. NAME          DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
  3. hello-world   Hello World! (an example of minimal Dockeriz…   2137      [OK]      
  4. [root@lh2022 Docker]#
复制代码
docker pull #下载镜像

docker pull 镜像名 #下载指定镜像,默认下载最新版本
docker pull 镜像名:版本号 #下载指定版本的镜像
默认下载最新版本的mysql。
  1. [root@lh2022 Docker]# docker pull mysql
  2. Using default tag: latest
  3. latest: Pulling from library/mysql
  4. 72a69066d2fe: Pull complete
  5. 93619dbc5b36: Pull complete
  6. 99da31dd6142: Pull complete
  7. 626033c43d70: Pull complete
  8. 37d5d7efb64e: Pull complete
  9. ac563158d721: Pull complete
  10. d2ba16033dad: Pull complete
  11. 688ba7d5c01a: Pull complete
  12. 00e060b6d11d: Pull complete
  13. 1c04857f594f: Pull complete
  14. 4d7cfa90e6ea: Pull complete
  15. e0431212d27d: Pull complete
  16. Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
  17. Status: Downloaded newer image for mysql:latest
  18. docker.io/library/mysql:latest
复制代码
下载指定版本的镜像。
  1. [root@lh2022 Docker]# docker pull mysql:5.7
  2. 5.7: Pulling from library/mysql
  3. 72a69066d2fe: Already exists
  4. 93619dbc5b36: Already exists
  5. 99da31dd6142: Already exists
  6. 626033c43d70: Already exists
  7. 37d5d7efb64e: Already exists
  8. ac563158d721: Already exists
  9. d2ba16033dad: Already exists
  10. 0ceb82207cd7: Pull complete
  11. 37f2405cae96: Pull complete
  12. e2482e017e53: Pull complete
  13. 70deed891d42: Pull complete
  14. Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
  15. Status: Downloaded newer image for mysql:5.7
  16. docker.io/library/mysql:5.7
复制代码
检察本地所以镜像,确认刚才的操作拉取成功。
  1. [root@lh2022 Docker]# docker images
  2. REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
  3. mysql         5.7       c20987f18b13   23 months ago   448MB
  4. mysql         latest    3218b38490ce   23 months ago   516MB
  5. hello-world   latest    feb5d9fea6a5   2 years ago     13.3kB
复制代码
docker rmi #删除镜像

docker rmi -f IMAGE ID #根据镜像的编号镜像删除,-f :force(强制)删除
  1. [root@lh2022 Docker]# docker rmi -f  feb5d9fea6a5
  2. Untagged: hello-world:latest
  3. Untagged: hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
  4. Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
  5. Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
  6. [root@lh2022 Docker]# docker images
  7. REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
  8. mysql        5.7       c20987f18b13   23 months ago   448MB
  9. mysql        latest    3218b38490ce   23 months ago   516MB
复制代码
docker rmi -f $(docker images -aq) #批量删除镜像
  1. [root@lh2022 Docker]# docker rmi $(docker images -aq)
  2. Untagged: mysql:5.7
  3. Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
  4. Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76
  5. Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989
  6. Deleted: sha256:0910f12649d514b471f1583a16f672ab67e3d29d9833a15dc2df50dd5536e40f
  7. Deleted: sha256:6682af2fb40555c448b84711c7302d0f86fc716bbe9c7dc7dbd739ef9d757150
  8. Deleted: sha256:5c062c3ac20f576d24454e74781511a5f96739f289edaadf2de934d06e910b92
  9. Untagged: mysql:latest
  10. Untagged: mysql@sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
  11. Deleted: sha256:3218b38490cec8d31976a40b92e09d61377359eab878db49f025e5d464367f3b
  12. Deleted: sha256:aa81ca46575069829fe1b3c654d9e8feb43b4373932159fe2cad1ac13524a2f5
  13. Deleted: sha256:0558823b9fbe967ea6d7174999be3cc9250b3423036370dc1a6888168cbd224d
  14. Deleted: sha256:a46013db1d31231a0e1bac7eeda5ad4786dea0b1773927b45f92ea352a6d7ff9
  15. Deleted: sha256:af161a47bb22852e9e3caf39f1dcd590b64bb8fae54315f9c2e7dc35b025e4e3
  16. Deleted: sha256:feff1495e6982a7e91edc59b96ea74fd80e03674d92c7ec8a502b417268822ff
  17. Deleted: sha256:8805862fcb6ef9deb32d4218e9e6377f35fb351a8be7abafdf1da358b2b287ba
  18. Deleted: sha256:872d2f24c4c64a6795e86958fde075a273c35c82815f0a5025cce41edfef50c7
  19. Deleted: sha256:6fdb3143b79e1be7181d32748dd9d4a845056dfe16ee4c827410e0edef5ad3da
  20. Deleted: sha256:b0527c827c82a8f8f37f706fcb86c420819bb7d707a8de7b664b9ca491c96838
  21. Deleted: sha256:75147f61f29796d6528486d8b1f9fb5d122709ea35620f8ffcea0e0ad2ab0cd0
  22. Deleted: sha256:2938c71ddf01643685879bf182b626f0a53b1356138ef73c40496182e84548aa
  23. Deleted: sha256:ad6b69b549193f81b039a1d478bc896f6e460c77c1849a4374ab95f9a3d2cea2
  24. [root@lh2022 Docker]# docker images
  25. REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
  26. [root@lh2022 Docker]#
复制代码
docker system df # 检察镜像/容器/数据卷所占的空间

  1. [root@lh2022 Docker]# docker system df
  2. TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
  3. Images          0         0         0B        0B
  4. Containers      0         0         0B        0B
  5. Local Volumes   0         0         0B        0B
  6. Build Cache     0         0         0B        0B
复制代码
容器下令:

docker pull 镜像名

有镜像才可以创建容器。之前批量删除了镜像,现在需要再拉取一些镜像:
docker pull centos
docker pull ubuntu

分别拉取最新版本的centos镜像和ubuntu镜像。
  1. [root@lh2022 Docker]# docker pull centos
  2. Using default tag: latest
  3. latest: Pulling from library/centos
  4. a1d0c7532777: Pull complete
  5. Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
  6. Status: Downloaded newer image for centos:latest
  7. docker.io/library/centos:latest
  8. [root@lh2022 Docker]# docker pull ubuntu
  9. Using default tag: latest
  10. latest: Pulling from library/ubuntu
  11. 7b1a6ab2e44d: Pull complete
  12. Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
  13. Status: Downloaded newer image for ubuntu:latest
  14. docker.io/library/ubuntu:latest
  15. [root@lh2022 Docker]#
复制代码
检察镜像,拉取成功。
  1. [root@lh2022 Docker]# docker images
  2. REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
  3. ubuntu       latest    ba6acccedd29   2 years ago   72.8MB
  4. centos       latest    5d0da3dc9764   2 years ago   231MB
复制代码
新建容器并启动
docker run [可选参数] image #启动容器

参数说明

  1. [root@lh2022 Docker]# docker run -it centos /bin/bash
  2. [root@930c0fbc66fb /]# ls
  3. bin  etc   lib      lost+found  mnt  proc  run   srv  tmp  var
  4. dev  home  lib64  media       opt  root  sbin  sys  usr
  5. [root@930c0fbc66fb /]# exit
  6. exit
  7. [root@lh2022 Docker]# docker run -it ubuntu /bin/bash
  8. root@0091bc9b9ff3:/# ls
  9. bin   dev  home  lib32  libx32  mnt  proc  run   srv  tmp  var
  10. boot  etc  lib   lib64  media   opt  root  sbin  sys  usr
  11. root@0091bc9b9ff3:/# exit
  12. exit
复制代码
docker ps #检察运行中的容器

docker ps -a #检察所有的容器(运行中的容器+运行过的容器)
docker ps -q #检察运行中的容器Id
docker ps -aq #检察所有的容器Id
检察运行中的容器。
  1. [root@lh2022 Docker]# docker ps
  2. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  3. [root@lh2022 Docker]#
复制代码
第二次创建并启动容器,且centos容器使用“Ctrl + Q + P”方式退出容器。Ubuntu容器直接“exit”退出容器。
  1. [root@lh2022 Docker]# docker run -it centos /bin/bash
  2. [root@d5268f5413d3 /]# [root@lh2022 Docker]#         
  3. [root@lh2022 Docker]# docker run -it ubuntu /bin/bash
  4. root@566457c9d521:/# exit
  5. exit
  6. [root@lh2022 Docker]# docker ps
  7. CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
  8. d5268f5413d3   centos    "/bin/bash"   2 minutes ago   Up 2 minutes             agitated_kapitsa
  9. [root@lh2022 Docker]#
复制代码
发现运行中的容器中有centos而没有Ubuntu,是因为他们的退出方式差别。这两种退出容器方式的区别:

  1. [root@lh2022 Docker]# docker ps -a
  2. CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS                          PORTS     NAMES
  3. 566457c9d521   ubuntu    "/bin/bash"   About a minute ago   Exited (0) About a minute ago             laughing_leavitt
  4. 2882d1edd0ac   ubuntu    "/bin/bash"   3 minutes ago        Exited (0) 2 minutes ago                  quirky_blackwell
  5. 87494ab4a5c9   ubuntu    "/bin/bash"   3 minutes ago        Exited (0) 3 minutes ago                  tender_carver
  6. d5268f5413d3   centos    "/bin/bash"   4 minutes ago        Up 4 minutes                              agitated_kapitsa
  7. 0091bc9b9ff3   ubuntu    "/bin/bash"   10 minutes ago       Exited (0) 9 minutes ago                  affectionate_pare
  8. 930c0fbc66fb   centos    "/bin/bash"   10 minutes ago       Exited (0) 10 minutes ago                 pensive_franklin
  9. [root@lh2022 Docker]#
复制代码
docker rm 容器id #删除容器

删除指定的容器不能删除正在运行的容器,如果要强制删除利用 -f “docker rm -f 容器id ”强制删除容器。
docker rm -f $(docker ps -aq) #删除所有的容器
docker ps -a -q | xargs docker rm #起首通过docker ps -a -q获取所有容器的ID列表,然后将这些ID列表作为参数转达给docker rm下令,以此来删除所有的容器。
注:xargs是给下令转达参数的一个过滤器,也是组合多个下令的一个工具。
检察运行中的容器id,并删除容器。
  1. [root@lh2022 Docker]# docker ps -q
  2. d5268f5413d3
  3. [root@lh2022 Docker]# docker rm d5268f5413d3
  4. Error response from daemon: You cannot remove a running container d5268f5413d3f1c7042fdf366a9257454ac827e0260a9195bbd2e6e9e475dc6a. Stop the container before attempting removal or force remove
  5. [root@lh2022 Docker]# docker rm -f d5268f5413d3
  6. d5268f5413d3
  7. [root@lh2022 Docker]# docker ps -q
  8. [root@lh2022 Docker]#
复制代码
发现正常的删除语句不能删除正在运行的容器,但是加上-f就可以强制删除成功。
删除所有的容器。
  1. [root@lh2022 Docker]# docker rm -f $(docker ps -aq)
  2. 566457c9d521
  3. 2882d1edd0ac
  4. 87494ab4a5c9
  5. 0091bc9b9ff3
  6. 930c0fbc66fb
  7. [root@lh2022 Docker]#
复制代码
创建一个新容器用后续容器的启动和停止操作。
  1. [root@lh2022 Docker]# docker run -it ubuntu /bin/bash
  2. root@23ba1c7ae31e:/# exit
  3. exit
  4. [root@lh2022 Docker]# docker ps -aq
  5. 23ba1c7ae31e
复制代码
docker start 容器id #启动容器

docker stop 容器id #停止当前正在运行的容器

docker restart 容器id #重启容器

docker kill 容器id #停止当前正在运行的容器

  1. [root@lh2022 Docker]# docker ps -aCONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES23ba1c7ae31e   ubuntu    "/bin/bash"   4 minutes ago   Exited (0) 4 minutes ago             optimistic_agnesi[root@lh2022 Docker]# docker start 23ba1c7ae31e23ba1c7ae31e[root@lh2022 Docker]# docker psCONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES23ba1c7ae31e   ubuntu    "/bin/bash"   4 minutes ago   Up 5 seconds             optimistic_agnesi[root@lh2022 Docker]# docker stop 23ba1c7ae31e23ba1c7ae31e[root@lh2022 Docker]# docker ps
  2. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  3. [root@lh2022 Docker]#
  4. docker restart 23ba1c7ae31e23ba1c7ae31e[root@lh2022 Docker]# docker psCONTAINER ID   IMAGE     COMMAND       CREATED         STATUS        PORTS     NAMES23ba1c7ae31e   ubuntu    "/bin/bash"   5 minutes ago   Up 1 second             optimistic_agnesi[root@lh2022 Docker]# docker kill 23ba1c7ae31e23ba1c7ae31e[root@lh2022 Docker]# docker ps
  5. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  6. [root@lh2022 Docker]#
复制代码
观察使用下令后的"STATUS "。
docker attach 容器名 #进入正在运行的容器

创建一个名叫ub1的容器,用“Ctrl + Q + P”退出容器但是不绝止运行。再用docker attach:重要的作用是进入正在运行的容器。
  1. [root@lh2022 Docker]# docker run -it --name ub1 ubuntu
  2. root@16683ac148d2:/# ls
  3. bin   dev  home  lib32  libx32  mnt  proc  run   srv  tmp  var
  4. boot  etc  lib   lib64  media   opt  root  sbin  sys  usr
  5. root@16683ac148d2:/# read escape sequence
  6. [root@lh2022 Docker]# docker ps -a
  7. CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS                    PORTS     NAMES
  8. 16683ac148d2   ubuntu    "bash"        About a minute ago   Up About a minute                   ub1
  9. 23ba1c7ae31e   ubuntu    "/bin/bash"   11 hours ago         Exited (0) 11 hours ago             optimistic_agnesi
  10. [root@lh2022 Docker]# docker attach ub1
  11. root@16683ac148d2:/# exit
  12. exit
  13. [root@lh2022 Docker]# docker ps -a
  14. CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
  15. 16683ac148d2   ubuntu    "bash"        2 minutes ago   Exited (0) 4 seconds ago             ub1
  16. 23ba1c7ae31e   ubuntu    "/bin/bash"   11 hours ago    Exited (0) 11 hours ago              optimistic_agnesi
  17. [root@lh2022 Docker]#
复制代码
docker commit : 重要功能为当前容器提交打包为镜像


  1. [root@lh2022 Docker]# docker images
  2. REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
  3. ubuntu       latest    ba6acccedd29   2 years ago   72.8MB
  4. centos       latest    5d0da3dc9764   2 years ago   231MB
  5. [root@lh2022 Docker]# docker ps -aCONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES16683ac148d2   ubuntu    "bash"        12 minutes ago   Exited (0) 10 minutes ago             ub123ba1c7ae31e   ubuntu    "/bin/bash"   11 hours ago     Exited (0) 11 hours ago               optimistic_agnesi[root@lh2022 Docker]# docker commit -a "lh" -m "my ubuntu,tag=v1 " 16683ac148d2 myubuntu:v1sha256:abfa3ff80204b3268c8756339627651dc2a2173bdce023eb7f2d4d7e17c1291a[root@lh2022 Docker]# docker imagesREPOSITORY   TAG       IMAGE ID       CREATED         SIZEmyubuntu     v1        abfa3ff80204   8 seconds ago   72.8MBubuntu       latest    ba6acccedd29   2 years ago     72.8MBcentos       latest    5d0da3dc9764   2 years ago     231MB[root@lh2022 Docker]#
复制代码
docker cp 下令

作用:雷同于Linux中的cp,用于在宿主机和容器之间移动复制文件
例子:把容器中的c_test.txt文件复制到宿主机中。
1、创建容器;
2、启动并进入容器;
3、在容器中/home/目次下创建c_test.txt;
4、使用cp下令完成复制。
实验环境:
主机本地/root/Docker下:
  1. [root@lh2022 Docker]# pwd
  2. /root/Docker
  3. [root@lh2022 Docker]# ls
  4. 2000
复制代码
进入容器:创建文件退却出容器但不绝止(CTRL+P+Q)。
  1. [root@lh2022 Docker]# docker ps -a
  2. CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
  3. 16683ac148d2   ubuntu    "bash"        21 minutes ago   Exited (0) 3 seconds ago             ub1
  4. 23ba1c7ae31e   ubuntu    "/bin/bash"   11 hours ago     Exited (0) 11 hours ago              optimistic_agnesi
  5. [root@lh2022 Docker]# docker start ub1
  6. ub1
  7. [root@lh2022 Docker]# docker attach ub1
  8. root@16683ac148d2:/# cd /home
  9. root@16683ac148d2:/home# ls
  10. root@16683ac148d2:/home# echo  "here is container~" > c_test.txt
  11. root@16683ac148d2:/home# ls
  12. c_test.txt
  13. root@16683ac148d2:/home# cat c_test.txt
  14. here is container~
  15. root@16683ac148d2:/home# read escape sequence
  16. [root@lh2022 Docker]#
复制代码
在主机使用docker cp 下令。
  1. [root@lh2022 Docker]# docker cp ub1:/home/c_test.txt  /root/Docker/
  2. Successfully copied 2.05kB to /root/Docker/
  3. [root@lh2022 Docker]# ls
  4. 2000  c_test.txt
  5. [root@lh2022 Docker]# cat c_test.txt
  6. here is container~
  7. [root@lh2022 Docker]#
复制代码
可以发现原来在主机/root/Docker 目次下是没有c_test.txt文件的,但是使用docker cp下令后,成功将容器中/home/c_test.txt复制到宿主机/root/Docker 目次下。
在宿主机中创建文件h_test.txt,使用cp下令将文件复制到容器/home/目次。
  1. [root@lh2022 Docker]# echo "这里是宿主机" > h_test.txt
  2. [root@lh2022 Docker]# ls
  3. 2000  c_test.txt  h_test.txt
  4. [root@lh2022 Docker]# docker cp h_test.txt ub1:/home/
  5. Successfully copied 2.05kB to ub1:/home/
  6. [root@lh2022 Docker]# docker attach ub1
  7. root@16683ac148d2:/home# ls
  8. c_test.txt  h_test.txt
  9. root@16683ac148d2:/home# cat h_test.txt
  10. 这里是宿主机
  11. root@16683ac148d2:/home#
复制代码
删除所有容器后。
  1. [root@lh2022 Docker]# docker rm $(docker ps -aq)
  2. 16683ac148d2
  3. 23ba1c7ae31e
  4. [root@lh2022 Docker]# docker ps -aq
  5. [root@lh2022 Docker]#
复制代码
docker create #创建容器但不启动的下令

用法同 docker run
通过docker create下令创建容器后,可以使用docker start containerID的方式启动容器。
  1. [root@lh2022 Docker]# docker create --name ub2 -it ubuntu /bin/bash
  2. 238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd
  3. [root@lh2022 Docker]# docker ps -a
  4. CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS    PORTS     NAMES
  5. 238e629747a4   ubuntu    "/bin/bash"   6 seconds ago   Created             ub2
  6. [root@lh2022 Docker]# docker start 238e629747a4
  7. 238e629747a4
  8. [root@lh2022 Docker]# docker ps -a
  9. CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS         PORTS     NAMES
  10. 238e629747a4   ubuntu    "/bin/bash"   About a minute ago   Up 2 seconds             ub2
  11. [root@lh2022 Docker]#
复制代码
可以发现使用docker create下令创建ub2容器后,ub2并没有自动启动运行。如果要启动它可以使用docker start containerID的方式启动容器。
pdocker diff #检察容器里文件结构的更改的下令

作用:可列出容器内发生厘革的文件和目次,厘革包罗(增,删,改)。
  1. [root@lh2022 Docker]# docker diff ub2
  2. [root@lh2022 Docker]# docker cp h_test.txt ub2:/home
  3. Successfully copied 2.05kB to ub2:/home
  4. [root@lh2022 Docker]# docker diff ub2
  5. C /home
  6. A /home/h_test.txt
  7. [root@lh2022 Docker]#
复制代码
docker events #检察变乱的下令

docker events下令用于检察Docker引擎的实时变乱。通过-f参数,可以过滤不须要的变乱,包罗容器、镜像、卷和网络相干的变乱。
  1. # 分屏1
  2. [root@lh2022 Docker]# docker events
  3. 2023-11-15T18:48:49.628580359-08:00 container kill 238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd (image=ubuntu, name=ub2, signal=15)
  4. 2023-11-15T18:48:49.757849329-08:00 network disconnect 8e75735fe85954df37e129075fb78291b9b0d9dbfc3f5a79e0d3db6d3dfd80bb (container=238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd, name=bridge, type=bridge)
  5. 2023-11-15T18:48:49.767037301-08:00 container stop 238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd (image=ubuntu, name=ub2)
  6. 2023-11-15T18:48:49.769831302-08:00 container die 238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd (execDuration=2466, exitCode=0, image=ubuntu, name=ub2)
  7. # 分配2
  8. [root@lh2022 Docker]# docker stop ub2
  9. ub2
  10. [root@lh2022 Docker]#
复制代码
以下是对各种变乱范例的整理:
1.容器相干变乱:

  1. # 分屏1
  2. [root@lh2022 Docker]# docker events -f container=ub2
  3. 2023-11-15T18:50:51.562283074-08:00 container start 238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd (image=ubuntu, name=ub2)
  4. # 分屏2
  5. [root@lh2022 Docker]# docker start ub2
  6. ub2
  7. [root@lh2022 Docker]#
复制代码
2.镜像相干变乱:

3.卷相干变乱:

4.网络相干变乱:

通过这些示例,可以过滤并检察特定范例的Docker变乱,以便更好地监控和管理Docker引擎的活动。
docker exec #进入容器的下令:

该下令重要用于进入容器内部进行操作。比attach功能更强大(exec使用率较高)

exec下令进入容器内部就如同进入另一台机器一样,可以灵活操作,而且使用exit下令退出时会像attach那样导致容器停止
  1. [root@lh2022 Docker]# docker ps -a
  2. CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS              PORTS     NAMES
  3. 238e629747a4   ubuntu    "/bin/bash"   45 minutes ago   Up About a minute             ub2
  4. [root@lh2022 Docker]# docker exec -it ub2 /bin/bash
  5. root@238e629747a4:/# exit
  6. exit
  7. [root@lh2022 Docker]# docker ps -a
  8. CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS     NAMES
  9. 238e629747a4   ubuntu    "/bin/bash"   46 minutes ago   Up 2 minutes             ub2
  10. [root@lh2022 Docker]# docker attach  ub2
  11. root@238e629747a4:/# exit
  12. exit
  13. [root@lh2022 Docker]# docker ps -a
  14. CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
  15. 238e629747a4   ubuntu    "/bin/bash"   46 minutes ago   Exited (0) 3 seconds ago             ub2
  16. [root@lh2022 Docker]#
复制代码
实现本地镜像的导出、导入(export、import、save、load)

docker export #导出容器的下令:

该下令用于导出本地存储的容器,导出的容器通常为tar包。
docker export -o /var/www/container.tar container
docker export container > /var/www/container.tar


注:使用 docker export 下令不会压缩容器大小
  1. [root@lh2022 Docker]# ls
  2. 2000  c_test.txt  h_test.txt
  3. [root@lh2022 Docker]# docker export -o ./ub2.tar ub2
  4. [root@lh2022 Docker]# ls
  5. 2000  c_test.txt  h_test.txt  ub2.tar
  6. [root@lh2022 Docker]# docker export ub2 > ./ubub.tar
  7. [root@lh2022 Docker]# ls
  8. 2000  c_test.txt  h_test.txt  ub2.tar  ubub.tar
  9. [root@lh2022 Docker]#
复制代码
docker import #导入容器的下令

该下令与 docker export下令相对,用于导入容器,从归档文件中创建一个镜像,导入后酿成镜像。
语法: docker import [OPTIONS] file |URL|- [REPOSITORY[:TAG]]
参数说明:

从本地导入:docker import /root/Docker/ub2.tar myubu:v2
  1. [root@lh2022 Docker]# docker images
  2. REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
  3. myubuntu     v1        abfa3ff80204   2 hours ago   72.8MB
  4. ubuntu       latest    ba6acccedd29   2 years ago   72.8MB
  5. centos       latest    5d0da3dc9764   2 years ago   231MB
  6. [root@lh2022 Docker]# docker import /root/Docker/ub2.tar myubu:v2
  7. sha256:4e5c141c83f093d74f9bc4491d01354a79a60d1dd81f633f07b6eb25e8693945
  8. [root@lh2022 Docker]# docker images
  9. REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
  10. myubu        v2        4e5c141c83f0   2 seconds ago   72.8MB
  11. myubuntu     v1        abfa3ff80204   2 hours ago     72.8MB
  12. ubuntu       latest    ba6acccedd29   2 years ago     72.8MB
  13. centos       latest    5d0da3dc9764   2 years ago     231MB
  14. [root@lh2022 Docker]#
复制代码
docker save #生存镜像

docker load #载入镜像

docker load下令用于导入使用docker save下令导出的镜像。通过该下令,可以将之前生存的镜像文件重新加载到Docker中。
常用参数:

例如,要导入名为ubuntu.tar的镜像文件,可以使用以下下令:
docker load -i ubuntu.tar
或者
docker load < ubuntu.tar
这将导入ubuntu.tar文件作为一个镜像。
需要留意的是,docker load下令只能导入镜像,无法导入容器。如果需要导出容器,请使用docker export下令;如果需要将容器导入为镜像,请使用docker import下令。
在导入镜像之前,通常需要先使用docker save下令将镜像导出为一个文件。例如,使用以下下令将名为myubuntu:v1的镜像导出为ub100.tar文件:
  1. [root@lh2022 Docker]# docker images
  2. REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
  3. myubu        v2        4e5c141c83f0   21 minutes ago   72.8MB
  4. myubuntu     v1        abfa3ff80204   2 hours ago      72.8MB
  5. ubuntu       latest    ba6acccedd29   2 years ago      72.8MB
  6. centos       latest    5d0da3dc9764   2 years ago      231MB
  7. [root@lh2022 Docker]# ls
  8. 2000  c_test.txt  h_test.txt  ub2.tar  ubub.tar
  9. [root@lh2022 Docker]# docker save -o ub100.tar myubuntu:v1
  10. [root@lh2022 Docker]# ls
  11. 2000  c_test.txt  h_test.txt  ub100.tar  ub2.tar  ubub.tar
  12. [root@lh2022 Docker]#
复制代码
再删除myubuntu:v1 镜像。
  1. [root@lh2022 Docker]# docker rmi myubuntu:v1
  2. Untagged: myubuntu:v1
  3. Deleted: sha256:abfa3ff80204b3268c8756339627651dc2a2173bdce023eb7f2d4d7e17c1291a
  4. Deleted: sha256:5154950c32caaca682dc87951263b479f8187c6c74b0eb9f5bec36e276087823
  5. [root@lh2022 Docker]# docker images
  6. REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
  7. myubu        v2        4e5c141c83f0   23 minutes ago   72.8MB
  8. ubuntu       latest    ba6acccedd29   2 years ago      72.8MB
  9. centos       latest    5d0da3dc9764   2 years ago      231MB
  10. [root@lh2022 Docker]#
复制代码
然后,可以使用docker load下令将ub100.tar文件导入为一个镜像。docker load -i ub100.tar 。
  1. [root@lh2022 Docker]# docker load -i ub100.tar
  2. 6914406b2a6b: Loading layer   2.56kB/2.56kB
  3. Loaded image: myubuntu:v1
  4. [root@lh2022 Docker]# docker images
  5. REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
  6. myubu        v2        4e5c141c83f0   24 minutes ago   72.8MB
  7. myubuntu     v1        abfa3ff80204   2 hours ago      72.8MB
  8. ubuntu       latest    ba6acccedd29   2 years ago      72.8MB
  9. centos       latest    5d0da3dc9764   2 years ago      231MB
  10. [root@lh2022 Docker]#
复制代码
再检察镜像发现导入成功。
总结起来,docker load下令用于导入使用docker save下令导出的镜像文件,是将之前生存的镜像重新加载到Docker中的操作。
export、import和save、load是两种差别的方法,不能混用。
导出和生存的格式差别:

导入和加载的方式差别:

文件大小差别:

是否可以对镜像重命名:

是否可以同时将多个镜像打包到一个文件中:

是否包含镜像汗青:

应用场景差别:

docker history #检察镜像汗青的下令:

该下令用于显示镜像的汗青,检察镜像的汗青厘革。
例:dockerhistory ubuntu:latest
  1. [root@lh2022 Docker]# docker history ubuntu:latest
  2. IMAGE          CREATED       CREATED BY                                       SIZE      COMMENT
  3. ba6acccedd29   2 years ago   /bin/sh -c #(nop)  CMD ["bash"]                  0B        
  4. <missing>      2 years ago   /bin/sh -c #(nop) ADD file:5d68d27cc15a80653…   72.8MB   
  5. [root@lh2022 Docker]# docker history myubu:v2
  6. IMAGE          CREATED          CREATED BY   SIZE      COMMENT
  7. 4e5c141c83f0   27 minutes ago                72.8MB    Imported from -
  8. [root@lh2022 Docker]# docker history myubuntu:v1
  9. IMAGE          CREATED       CREATED BY                                       SIZE      COMMENT
  10. abfa3ff80204   2 hours ago   bash                                             8B        my ubuntu,tag=v1
  11. <missing>      2 years ago   /bin/sh -c #(nop)  CMD ["bash"]                  0B        
  12. <missing>      2 years ago   /bin/sh -c #(nop) ADD file:5d68d27cc15a80653…   72.8MB   
复制代码
docker inspect #检察各项详细信息的下令:

获取容器/镜像的元数据。
语法:docker inspect [OPTIONS] NAME|ID [NAME|ID…]
OPTIONS说明:

例:以ub1容器为例
此下令可以检察容器:IP地址、Mac地址、日志等等
  1. [root@lh2022 Docker]# docker inspect ub2
  2. [
  3.     {
  4.         "Id": "238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd",
  5.         "Created": "2023-11-16T02:06:36.095363783Z",
  6.         "Path": "/bin/bash",
  7.         "Args": [],
  8.         "State": {
  9.             "Status": "exited",
  10.             "Running": false,
  11.             "Paused": false,
  12.             "Restarting": false,
  13.             "OOMKilled": false,
  14.             "Dead": false,
  15.             "Pid": 0,
  16.             "ExitCode": 0,
  17.             "Error": "",
  18.             "StartedAt": "2023-11-16T02:50:51.557878979Z",
  19.             "FinishedAt": "2023-11-16T02:53:29.19971954Z"
  20.         },
  21.         "Image": "sha256:ba6acccedd2923aee4c2acc6a23780b14ed4b8a5fa4e14e252a23b846df9b6c1",
  22.         "ResolvConfPath": "/var/lib/docker/containers/238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd/resolv.conf",
  23.         "HostnamePath": "/var/lib/docker/containers/238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd/hostname",
  24.         "HostsPath": "/var/lib/docker/containers/238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd/hosts",
  25.         "LogPath": "/var/lib/docker/containers/238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd/238e629747a48a847af3d9300ce007f5c47884ffcd6029339b099215bf5055bd-json.log",
  26.         "Name": "/ub2",
  27.         "RestartCount": 0,
  28.         "Driver": "overlay2",
  29.         "Platform": "linux",
  30.         "MountLabel": "",
  31.         "ProcessLabel": "",
  32.         "AppArmorProfile": "",
  33.         "ExecIDs": null,
  34.         "HostConfig": {
  35.             "Binds": null,
  36.             "ContainerIDFile": "",
  37.             "LogConfig": {
  38.                 "Type": "json-file",
  39.                 "Config": {}
  40.             },
  41.             "NetworkMode": "default",
  42.             "PortBindings": {},
  43.             "RestartPolicy": {
  44.                 "Name": "no",
  45.                 "MaximumRetryCount": 0
  46.             },
  47.             "AutoRemove": false,
  48.             "VolumeDriver": "",
  49.             "VolumesFrom": null,
  50.             "ConsoleSize": [
  51.                 17,
  52.                 95
  53.             ],
  54.             "CapAdd": null,
  55.             "CapDrop": null,
  56.             "CgroupnsMode": "host",
  57.             "Dns": [],
  58.             "DnsOptions": [],
  59.             "DnsSearch": [],
  60.             "ExtraHosts": null,
  61.             "GroupAdd": null,
  62.             "IpcMode": "private",
  63.             "Cgroup": "",
  64.             "Links": null,
  65.             "OomScoreAdj": 0,
  66.             "PidMode": "",
  67.             "Privileged": false,
  68.             "PublishAllPorts": false,
  69.             "ReadonlyRootfs": false,
  70.             "SecurityOpt": null,
  71.             "UTSMode": "",
  72.             "UsernsMode": "",
  73.             "ShmSize": 67108864,
  74.             "Runtime": "runc",
  75.             "Isolation": "",
  76.             "CpuShares": 0,
  77.             "Memory": 0,
  78.             "NanoCpus": 0,
  79.             "CgroupParent": "",
  80.             "BlkioWeight": 0,
  81.             "BlkioWeightDevice": [],
  82.             "BlkioDeviceReadBps": [],
  83.             "BlkioDeviceWriteBps": [],
  84.             "BlkioDeviceReadIOps": [],
  85.             "BlkioDeviceWriteIOps": [],
  86.             "CpuPeriod": 0,
  87.             "CpuQuota": 0,
  88.             "CpuRealtimePeriod": 0,
  89.             "CpuRealtimeRuntime": 0,
  90.             "CpusetCpus": "",
  91.             "CpusetMems": "",
  92.             "Devices": [],
  93.             "DeviceCgroupRules": null,
  94.             "DeviceRequests": null,
  95.             "MemoryReservation": 0,
  96.             "MemorySwap": 0,
  97.             "MemorySwappiness": null,
  98.             "OomKillDisable": false,
  99.             "PidsLimit": null,
  100.             "Ulimits": null,
  101.             "CpuCount": 0,
  102.             "CpuPercent": 0,
  103.             "IOMaximumIOps": 0,
  104.             "IOMaximumBandwidth": 0,
  105.             "MaskedPaths": [
  106.                 "/proc/asound",
  107.                 "/proc/acpi",
  108.                 "/proc/kcore",
  109.                 "/proc/keys",
  110.                 "/proc/latency_stats",
  111.                 "/proc/timer_list",
  112.                 "/proc/timer_stats",
  113.                 "/proc/sched_debug",
  114.                 "/proc/scsi",
  115.                 "/sys/firmware",
  116.                 "/sys/devices/virtual/powercap"
  117.             ],
  118.             "ReadonlyPaths": [
  119.                 "/proc/bus",
  120.                 "/proc/fs",
  121.                 "/proc/irq",
  122.                 "/proc/sys",
  123.                 "/proc/sysrq-trigger"
  124.             ]
  125.         },
  126.         "GraphDriver": {
  127.             "Data": {
  128.                 "LowerDir": "/var/lib/docker/overlay2/cc7de16eeedc3032ee3e4d63e43f4eec607d861ed87000a58f1473b93ffb4c6f-init/diff:/var/lib/docker/overlay2/81040a27ad2991a0f03d38a70d3f541dc867955b596d36671bbcc4ff89e80b66/diff",
  129.                 "MergedDir": "/var/lib/docker/overlay2/cc7de16eeedc3032ee3e4d63e43f4eec607d861ed87000a58f1473b93ffb4c6f/merged",
  130.                 "UpperDir": "/var/lib/docker/overlay2/cc7de16eeedc3032ee3e4d63e43f4eec607d861ed87000a58f1473b93ffb4c6f/diff",
  131.                 "WorkDir": "/var/lib/docker/overlay2/cc7de16eeedc3032ee3e4d63e43f4eec607d861ed87000a58f1473b93ffb4c6f/work"
  132.             },
  133.             "Name": "overlay2"
  134.         },
  135.         "Mounts": [],
  136.         "Config": {
  137.             "Hostname": "238e629747a4",
  138.             "Domainname": "",
  139.             "User": "",
  140.             "AttachStdin": true,
  141.             "AttachStdout": true,
  142.             "AttachStderr": true,
  143.             "Tty": true,
  144.             "OpenStdin": true,
  145.             "StdinOnce": true,
  146.             "Env": [
  147.                 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  148.             ],
  149.             "Cmd": [
  150.                 "/bin/bash"
  151.             ],
  152.             "Image": "ubuntu",
  153.             "Volumes": null,
  154.             "WorkingDir": "",
  155.             "Entrypoint": null,
  156.             "OnBuild": null,
  157.             "Labels": {}
  158.         },
  159.         "NetworkSettings": {
  160.             "Bridge": "",
  161.             "SandboxID": "c19b11e3e2d34dce5d767270e64a89e83c29c90e4cc43954b577e4759cdc06d4",
  162.             "HairpinMode": false,
  163.             "LinkLocalIPv6Address": "",
  164.             "LinkLocalIPv6PrefixLen": 0,
  165.             "Ports": {},
  166.             "SandboxKey": "/var/run/docker/netns/c19b11e3e2d3",
  167.             "SecondaryIPAddresses": null,
  168.             "SecondaryIPv6Addresses": null,
  169.             "EndpointID": "",
  170.             "Gateway": "",
  171.             "GlobalIPv6Address": "",
  172.             "GlobalIPv6PrefixLen": 0,
  173.             "IPAddress": "",
  174.             "IPPrefixLen": 0,
  175.             "IPv6Gateway": "",
  176.             "MacAddress": "",
  177.             "Networks": {
  178.                 "bridge": {
  179.                     "IPAMConfig": null,
  180.                     "Links": null,
  181.                     "Aliases": null,
  182.                     "NetworkID": "8e75735fe85954df37e129075fb78291b9b0d9dbfc3f5a79e0d3db6d3dfd80bb",
  183.                     "EndpointID": "",
  184.                     "Gateway": "",
  185.                     "IPAddress": "",
  186.                     "IPPrefixLen": 0,
  187.                     "IPv6Gateway": "",
  188.                     "GlobalIPv6Address": "",
  189.                     "GlobalIPv6PrefixLen": 0,
  190.                     "MacAddress": "",
  191.                     "DriverOpts": null
  192.                 }
  193.             }
  194.         }
  195.     }
  196. ]
  197. [root@lh2022 Docker]#
  198. [root@lh2022 Docker]# docker inspect --format='{{range.NetworkSettings.Networks}}{{.NetworkID}}{{end}}' ub2
  199. 8e75735fe85954df37e129075fb78291b9b0d9dbfc3f5a79e0d3db6d3dfd80bb
复制代码
docker kill #杀死容器的下令:

该下令用于快速杀掉容器的进程,常用于无法停止容器的时候,使用docker kill下令可以让一个无响应的容器停止。
与docker stop的区别:给容器发送差别的信号,stop下令将会发送SIGTERM信号,容器接收到此信号的默认举动会导致容器退出,同时也允许容器内的步调自行处理,而kill发出的信号为SIGKILL信号,此信号使得容器必然退出。
  1. [root@lh2022 Docker]# docker ps -a
  2. CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS         PORTS     NAMES
  3. 238e629747a4   ubuntu    "/bin/bash"   2 hours ago   Up 2 seconds             ub2
  4. [root@lh2022 Docker]# docker kill ub2
  5. ub2
  6. [root@lh2022 Docker]# docker ps -a
  7. CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS                      PORTS     NAMES
  8. 238e629747a4   ubuntu    "/bin/bash"   2 hours ago   Exited (137) 1 second ago             ub2
  9. [root@lh2022 Docker]#
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4