docker(5):docker的镜像操作

柔情只为你懂 2021-10-29 15:14 504阅读 0赞

docker(5):docker的镜像操作

1 搜索**镜像**docker search XXX

例如搜索Nginx

  1. [root@docker-136 ~]# docker search nginx
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. nginx Official build of Nginx. 11785 [OK]
  4. jwilder/nginx-proxy Automated Nginx reverse proxy for docker con 1635 [OK]
  5. richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of 731 [OK]
  6. ……..

搜索结果解释:




























参数

说明

NAME

镜像名称

DESCRIPTION

镜像说明

STARS

点赞数量

OFFICIAL

是否是官方的

AUTOMATED

是否是自动构建的

2 获取镜像docker pull XXX

  1. 不指定版本默认为最新版,只写名字默认在官方拉取
  2. [root@docker-136 ~]# docker pull httpd
  3. Using default tag: latest
  4. latest: Pulling from library/httpd
  5. f5d23c7fed46: Already exists
  6. b083c5fd185b: Pull complete
  7. bf5100a89e78: Pull complete
  8. 98f47fcaa52f: Pull complete
  9. 622a9dd8cfed: Pull complete
  10. Digest: sha256:dc4c86bc90593c6e4c5b06872a7a363fc7d4eec99c5d6bfac881f7371adcb2c4
  11. Status: Downloaded newer image for httpd:latest
  12. docker.io/library/httpd:latest
  13. [root@docker-136 ~]#

拉取指定版本docker pull httpd:2.2

  1. [root@docker-136 ~]# docker pull httpd:2.2
  2. 2.2: Pulling from library/httpd
  3. f49cf87b52c1: Pull complete
  4. 24b1e09cbcb7: Pull complete
  5. 8a4e0d64e915: Pull complete
  6. bcbe0eb4ca51: Pull complete
  7. 16e370c15d38: Pull complete
  8. Digest: sha256:9784d70c8ea466fabd52b0bc8cde84980324f9612380d22fbad2151df9a430eb
  9. Status: Downloaded newer image for httpd:2.2
  10. docker.io/library/httpd:2.2
  11. [root@docker-136 ~]# docker images
  12. REPOSITORY TAG IMAGE ID CREATED SIZE
  13. nginx latest e445ab08b2be 13 days ago 126MB
  14. httpd latest ee39f68eb241 3 weeks ago 154MB
  15. hello-world latest fce289e99eb9 7 months ago 1.84kB
  16. httpd 2.2 e06c3dbbfe23 18 months ago 171MB
  17. [root@docker-136 ~]#

3 查看镜像docker images/docker image ls

  1. [root@docker-136 ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest e445ab08b2be 13 days ago 126MB
  4. httpd latest ee39f68eb241 3 weeks ago 154MB
  5. hello-world latest fce289e99eb9 7 months ago 1.84kB
  6. [root@docker-136 ~]#

4 导出镜像**docker image save XX >*.tar.gz**

  1. [root@docker-136 ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest e445ab08b2be 13 days ago 126MB
  4. httpd latest ee39f68eb241 3 weeks ago 154MB
  5. hello-world latest fce289e99eb9 7 months ago 1.84kB
  6. httpd 2.2 e06c3dbbfe23 18 months ago 171MB
  7. [root@docker-136 ~]# docker save httpd:2.2 > docker_httpd_2.2.tar.gz
  8. [root@docker-136 ~]# ls
  9. audit.py docker_httpd_2.2.tar.gz MadKingClient p.txt ssh.log ssh_test.py tools
  10. [root@docker-136 ~]#

5 删除镜像docker image rm XXX

  1. [root@docker-136 ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest e445ab08b2be 13 days ago 126MB
  4. httpd latest ee39f68eb241 3 weeks ago 154MB
  5. hello-world latest fce289e99eb9 7 months ago 1.84kB
  6. httpd 2.2 e06c3dbbfe23 18 months ago 171MB
  7. [root@docker-136 ~]# docker image rm httpd:2.2
  8. Untagged: httpd:2.2
  9. Untagged: httpd@sha256:9784d70c8ea466fabd52b0bc8cde84980324f9612380d22fbad2151df9a430eb
  10. Deleted: sha256:e06c3dbbfe239c6fca50b6ab6935b3122930fa2eea2136979e5b46ad77ecb685
  11. Deleted: sha256:aefd81e57d336a46bb1eb4c4626a3f971759e0e9651e348d5e83b301614b4522
  12. Deleted: sha256:b85fe9130aef01e870e6d0a108fd003cf803d5da7fe479513a21de0643d7ecae
  13. Deleted: sha256:40154da5ddb3570d82395b9c632880baca5f12ad21ea8c699f3897cd5ed9b237
  14. Deleted: sha256:f5863aa45770c31d7555287f821930e41bc466b97464733ccf980f16393d99d9
  15. Deleted: sha256:4bcdffd70da292293d059d2435c7056711fab2655f8b74f48ad0abe042b63687
  16. [root@docker-136 ~]# docker images
  17. REPOSITORY TAG IMAGE ID CREATED SIZE
  18. nginx latest e445ab08b2be 13 days ago 126MB
  19. httpd latest ee39f68eb241 3 weeks ago 154MB
  20. hello-world latest fce289e99eb9 7 months ago 1.84kB
  21. [root@docker-136 ~]#

6 导入镜像docker image load –i XXX

  1. [root@docker-136 ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest e445ab08b2be 13 days ago 126MB
  4. httpd latest ee39f68eb241 3 weeks ago 154MB
  5. hello-world latest fce289e99eb9 7 months ago 1.84kB
  6. [root@docker-136 ~]#
  7. [root@docker-136 ~]# docker image load -i docker_httpd_2.2.tar.gz
  8. 4bcdffd70da2: Loading layer [==================================================>] 129.3MB/129.3MB
  9. 71436bd6f1c4: Loading layer [==================================================>] 2.56kB/2.56kB
  10. 3f7f50ced288: Loading layer [==================================================>] 43.86MB/43.86MB
  11. 9058feb62b4a: Loading layer [==================================================>] 6.896MB/6.896MB
  12. ab5efd5aec77: Loading layer [==================================================>] 3.584kB/3.584kB
  13. Loaded image: httpd:2.2
  14. [root@docker-136 ~]# docker images
  15. REPOSITORY TAG IMAGE ID CREATED SIZE
  16. nginx latest e445ab08b2be 13 days ago 126MB
  17. httpd latest ee39f68eb241 3 weeks ago 154MB
  18. hello-world latest fce289e99eb9 7 months ago 1.84kB
  19. httpd 2.2 e06c3dbbfe23 18 months ago 171MB
  20. [root@docker-136 ~]#

7 查看镜像的详细信息docker image inspect

ContractedBlock.gif ExpandedBlockStart.gif

  1. [root@docker-136 ~]# docker image inspect nginx
  2. [
  3. {
  4. "Id": "sha256:e445ab08b2be8b178655b714f89e5db9504f67defd5c7408a00bade679a50d44",
  5. "RepoTags": [
  6. "nginx:latest"
  7. ],
  8. "RepoDigests": [
  9. "nginx@sha256:eb3320e2f9ca409b7c0aa71aea3cf7ce7d018f03a372564dbdb023646958770b"
  10. ],
  11. "Parent": "",
  12. "Comment": "",
  13. "Created": "2019-07-23T19:59:08.879181657Z",
  14. "Container": "c863d9d5564c77538fa9ae5d46d088aeff1fe21f21da3af224b2ebf9e5dafe73",
  15. "ContainerConfig": {
  16. "Hostname": "c863d9d5564c",
  17. "Domainname": "",
  18. "User": "",
  19. "AttachStdin": false,
  20. "AttachStdout": false,
  21. "AttachStderr": false,
  22. "ExposedPorts": {
  23. "80/tcp": {}
  24. },
  25. "Tty": false,
  26. "OpenStdin": false,
  27. "StdinOnce": false,
  28. "Env": [
  29. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  30. "NGINX_VERSION=1.17.2",
  31. "NJS_VERSION=0.3.3",
  32. "PKG_RELEASE=1~buster"
  33. ],
  34. "Cmd": [
  35. "/bin/sh",
  36. "-c",
  37. "#(nop) ",
  38. "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
  39. ],
  40. "ArgsEscaped": true,
  41. "Image": "sha256:efa26677587b22b262ca9d50b41608a85c6f86e05b16f98da4e762ab6223a31a",
  42. "Volumes": null,
  43. "WorkingDir": "",
  44. "Entrypoint": null,
  45. "OnBuild": null,
  46. "Labels": {
  47. "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
  48. },
  49. "StopSignal": "SIGTERM"
  50. },
  51. "DockerVersion": "18.06.1-ce",
  52. "Author": "",
  53. "Config": {
  54. "Hostname": "",
  55. "Domainname": "",
  56. "User": "",
  57. "AttachStdin": false,
  58. "AttachStdout": false,
  59. "AttachStderr": false,
  60. "ExposedPorts": {
  61. "80/tcp": {}
  62. },
  63. "Tty": false,
  64. "OpenStdin": false,
  65. "StdinOnce": false,
  66. "Env": [
  67. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  68. "NGINX_VERSION=1.17.2",
  69. "NJS_VERSION=0.3.3",
  70. "PKG_RELEASE=1~buster"
  71. ],
  72. "Cmd": [
  73. "nginx",
  74. "-g",
  75. "daemon off;"
  76. ],
  77. "ArgsEscaped": true,
  78. "Image": "sha256:efa26677587b22b262ca9d50b41608a85c6f86e05b16f98da4e762ab6223a31a",
  79. "Volumes": null,
  80. "WorkingDir": "",
  81. "Entrypoint": null,
  82. "OnBuild": null,
  83. "Labels": {
  84. "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
  85. },
  86. "StopSignal": "SIGTERM"
  87. },
  88. "Architecture": "amd64",
  89. "Os": "linux",
  90. "Size": 125850346,
  91. "VirtualSize": 125850346,
  92. "GraphDriver": {
  93. "Data": {
  94. "LowerDir": "/var/lib/docker/overlay2/3b3bdb780578fb73e3790a01ee64f882827efbc55a2033e77724422aa266a81b/diff:/var/lib/docker/overlay2/e1aa1fea00354331c6473874dadcc26c37367a93272c99e9a9152386f865f674/diff",
  95. "MergedDir": "/var/lib/docker/overlay2/2164493c0285dd83915545bdbc41f4bac079db401c236ff2301e8793445b4a86/merged",
  96. "UpperDir": "/var/lib/docker/overlay2/2164493c0285dd83915545bdbc41f4bac079db401c236ff2301e8793445b4a86/diff",
  97. "WorkDir": "/var/lib/docker/overlay2/2164493c0285dd83915545bdbc41f4bac079db401c236ff2301e8793445b4a86/work"
  98. },
  99. "Name": "overlay2"
  100. },
  101. "RootFS": {
  102. "Type": "layers",
  103. "Layers": [
  104. "sha256:d8a33133e477d367977987129313d9072e0ec80894ed4c52c2d88186f354c29a",
  105. "sha256:d0673244f7d49ae9ae0644216eab054081add3b4af4afecea2f885e722367719",
  106. "sha256:fe6a7a3b3f27025052f52b030f77d2ccf222bfd5af25522fbd418e4b9c91f325"
  107. ]
  108. },
  109. "Metadata": {
  110. "LastTagTime": "0001-01-01T00:00:00Z"
  111. }
  112. }
  113. ]

转载于:https://www.cnblogs.com/wangxu01/articles/11310404.html

发表评论

表情:
评论列表 (有 0 条评论,504人围观)

还没有评论,来说两句吧...

相关阅读