美文网首页容器技术
十二、镜像的基本操作

十二、镜像的基本操作

作者: InsaneLoafer | 来源:发表于2021-12-04 19:50 被阅读0次

镜像的基本操作

$ docker image

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.

查看镜像的分层(layer)

docker image history <image_name>

[root@localhost ~]# docker image history insaneloafer/hello:1.0
IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT
e3a733c6921a   24 hours ago   /bin/sh -c #(nop)  CMD ["python3" "/hello.py…   0B
<missing>      24 hours ago   /bin/sh -c #(nop) ADD file:d739451e741e82c2f…   22B
<missing>      24 hours ago   /bin/sh -c apt-get update &&     DEBIAN_FRON…   127MB
<missing>      7 weeks ago    /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>      7 weeks ago    /bin/sh -c #(nop) ADD file:3a18768000089a105…   80MB

镜像的拉取Pull Image

默认从Docker Hub拉取,如果不指定版本,会拉取最新版

$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete
49f7d34d62c1: Pull complete
5f97dc5d71ab: Pull complete
cfcd0711b93a: Pull complete
be6172d7651b: Pull complete
de9813870342: Pull complete
Digest: sha256:df13abe416e37eb3db4722840dd479b00ba193ac6606e7902331dcea50f4f1f2
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

指定版本

$ docker pull nginx:1.20.0
1.20.0: Pulling from library/nginx
69692152171a: Already exists
965615a5cec8: Pull complete
b141b026b9ce: Pull complete
8d70dc384fb3: Pull complete
525e372d6dee: Pull complete
Digest: sha256:ea4560b87ff03479670d15df426f7d02e30cb6340dcd3004cdfc048d6a1d54b4
Status: Downloaded newer image for nginx:1.20.0
docker.io/library/nginx:1.20.0

从Quay上拉取镜像

$ docker pull quay.io/bitnami/nginx
Using default tag: latest
latest: Pulling from bitnami/nginx
2e6370f1e2d3: Pull complete
2d464c695e97: Pull complete
83eb3b1671f4: Pull complete
364c139450f9: Pull complete
dc453d5ae92e: Pull complete
09bd59934b83: Pull complete
8d2bd62eedfb: Pull complete
8ac060ae1ede: Pull complete
c7c9bc2f4f9d: Pull complete
6dd7098b85fa: Pull complete
894a70299d18: Pull complete
Digest: sha256:d143befa04e503472603190da62db157383797d281fb04e6a72c85b48e0b3239
Status: Downloaded newer image for quay.io/bitnami/nginx:latest
quay.io/bitnami/nginx:latest

镜像的查看

$ docker image ls
REPOSITORY              TAG       IMAGE ID       CREATED       SIZE
quay.io/bitnami/nginx   latest    0922eabe1625   6 hours ago   89.3MB
nginx                   1.20.0    7ab27dbbfbdf   10 days ago   133MB
nginx                   latest    f0b8a9a54136   10 days ago   133MB
  • 详细查看某个镜像的信息:docker image inspect <image ID>
$ docker image inspect 94b72494607b
[
    {
        "Id": "sha256:94b72494607b406caa2e2c0f3d79d6c49fd4d65fd56688ec0171a1f2b356bb2d",
        "RepoTags": [
            "quay.io/bitnami/nginx:latest"
        ],
        "RepoDigests": [
            "quay.io/bitnami/nginx@sha256:0caf2be99c1f13a6a5c5c7c38c1e472b413ca62160d3be2cfd0d30d62af7d8f5"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2021-11-23T02:18:43.577193295Z",
        "Container": "e51d3aaafbf51cd81b13cf1d8ac5f3a733b3ab1e9086f13030d27a9a5f14c503",
        "ContainerConfig": {
            "Hostname": "e51d3aaafbf5",
            "Domainname": "",
            "User": "1001",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8080/tcp": {},
                "8443/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/opt/bitnami/common/bin:/opt/bitnami/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "HOME=/",
                "OS_ARCH=amd64",
                "OS_FLAVOUR=debian-10",
                "OS_NAME=linux",
                "BITNAMI_APP_NAME=nginx",
                "BITNAMI_IMAGE_VERSION=1.21.4-debian-10-r19",
                "NGINX_ENABLE_CUSTOM_PORTS=no",
                "NGINX_HTTPS_PORT_NUMBER=",
                "NGINX_HTTP_PORT_NUMBER="
            ],
...

镜像的删除

$ docker image rm 0922eabe1625
Untagged: quay.io/bitnami/nginx:latest
Untagged: quay.io/bitnami/nginx@sha256:d143befa04e503472603190da62db157383797d281fb04e6a72c85b48e0b3239
Deleted: sha256:0922eabe16250e2f4711146e31b7aac0e547f52daa6cf01c9d00cf64d49c68c8
Deleted: sha256:5eee4ed0f6b242e2c6e4f4066c7aca26bf9b3b021b511b56a0dadd52610606bd
Deleted: sha256:472a75325eda417558f9100ff8b4a97f4a5e8586a14eb9c8fc12f944b26a21f8
Deleted: sha256:cdcb5872f8a64a0b5839711fcd2a87ba05795e5bf6a70ba9510b8066cdd25e76
Deleted: sha256:e0f1b7345a521469bbeb7ec53ef98227bd38c87efa19855c5ba0db0ac25c8e83
Deleted: sha256:11b9c2261cfc687fba8d300b83434854cc01e91a2f8b1c21dadd937e59290c99
Deleted: sha256:4819311ec2867ad82d017253500be1148fc335ad13b6c1eb6875154da582fcf2
Deleted: sha256:784480add553b8e8d5ee1bbd229ed8be92099e5fb61009ed7398b93d5705a560
Deleted: sha256:e0c520d1a43832d5d2b1028e3f57047f9d9f71078c0187f4bb05e6a6a572993d
Deleted: sha256:94d5b1d6c9e31de42ce58b8ce51eb6fb5292ec889a6d95763ad2905330b92762
Deleted: sha256:95deba55c490bbb8de44551d3e6a89704758c93ba8503a593cb7c07dfbae0058
Deleted: sha256:1ad1d903ef1def850cd44e2010b46542196e5f91e53317dbdb2c1eedfc2d770

Note
正在运行的container和停止掉但是没有删除的container,不能删除其image。


image.png

相关文章

  • 十二、镜像的基本操作

    镜像的基本操作[https://dockertips.readthedocs.io/en/latest/docke...

  • docker基本操作

    # docker基本操作 ## 镜像操作 ### 获取镜像 从Docker Hub搜索镜像: docker s...

  • Docker基础操作手册

    Docker操作总结 @Date 2018.08.24 基本操作 登录远程镜像仓库 镜像操作 根据指定路径的Doc...

  • Docker 语法快速预览

    安装 基本概念 镜像: 一个操作系统 容器: 一个操作系统的实例 仓库: 存储镜像的地方 镜像使用 查找镜像doc...

  • Docker镜像的基本操作

    Docker Image镜像 容器的基石 层叠的只读文件 联合加载(Union mount) 文件位置: /var...

  • Docker镜像的基本操作

    获取镜像 查看镜像列表 虚悬镜像 上面的镜像列表中,还可以看到一个特殊的镜像,这个镜像既没有仓库名,也没有标签,均...

  • docker 基本命令

    一,关于docker镜像操作的基本命令 二,关于docker容器操作的基本命令 三,关于docker仓库操作的基本命令

  • docker命令

    镜像、容器基本操作 1、获取镜像docker pull 2、运行容器docker run docker run -...

  • Docker入门及安装

    1.卸载 2.CentOS7中安装 3.docker基本操作 容器操作 镜像操作

  • docker笔记(2)----docker容器连接

    Dockerfile基本结构: 基础镜像内容:FROM指明base image 维护者信息: 镜像操作指令:RUN...

网友评论

    本文标题:十二、镜像的基本操作

    本文链接:https://www.haomeiwen.com/subject/orgwtrtx.html