0
点赞
收藏
分享

微信扫一扫

docker 镜像操作

小暴龙要抱抱 2022-01-21 阅读 50

常用命令

下载镜像

如果想要在本地运行容器,就必须保证本地存在对应的镜像。所以第一步,需要下载镜像。当尝试下载镜像时,Docker 会尝试先从默认的镜像仓库(hub.docker.com)搜索你要的镜像,然后根据页面提示下载,命令格式如下:

docker pull [镜像名]:[镜像标签TAG]

举例:
下载centos

在这里插入图片描述

当不指定TAG时,默认下载latest标签,也就是仓库中最新的版本

docker pull centos

# 下载指定版本
docker pull centos:centos8.4.2105

查看镜像列表

docker image ls
docker images

结果:
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   4 months ago   231MB

REPOSITORY: 仓库

TAG: 镜像的标签信息,比如 centos8.4.2105、latest 表示不同的版本信息

IMAGE ID: 镜像的 ID

CREATED: 镜像最后的更新时间

SIZE: 镜像的大小

查看镜像详细信息

docker inspect [镜像名]
docker inspect centos

结果:
[
    {
        "Id": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "RepoTags": [
            "centos:latest"
        ],
        "RepoDigests": [
            "centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2021-09-15T18:20:05.184694267Z",
        "Container": "9bf8a9e2ddff4c0d76a587c40239679f29c863a967f23abf7a5babb6c2121bf1",
        "ContainerConfig": {
            "Hostname": "9bf8a9e2ddff",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/bin/bash\"]"
            ],
            "Image": "sha256:f5b050f177fd426be8fe998a8ecf3fb1858d7e26dff4080b29a327d1bd5ba422",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "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/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "sha256:f5b050f177fd426be8fe998a8ecf3fb1858d7e26dff4080b29a327d1bd5ba422",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 231268856,
        "VirtualSize": 231268856,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/edb70954e9bbaad188303504a5c16afda4c050ab8f381ae7a35d30cebd249599/merged",
                "UpperDir": "/var/lib/docker/overlay2/edb70954e9bbaad188303504a5c16afda4c050ab8f381ae7a35d30cebd249599/diff",
                "WorkDir": "/var/lib/docker/overlay2/edb70954e9bbaad188303504a5c16afda4c050ab8f381ae7a35d30cebd249599/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

仓库中搜索镜像

docker search [镜像名]
docker search centos

结果:
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                            The official build of CentOS.                   6981      [OK]       
ansible/centos7-ansible           Ansible on Centos7                              135                  [OK]
consol/centos-xfce-vnc            Centos container with "headless" VNC session…   135                  [OK]
jdeathe/centos-ssh                OpenSSH / Supervisor / EPEL/IUS/SCL Repos -121                  [OK]
centos/systemd                    systemd enabled base container.                 105                  [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   92                   
imagine10255/centos6-lnmp-php56   centos6-lnmp-php56                              58                   [OK]
tutum/centos                      Simple CentOS docker image with SSH access      48                   
centos/postgresql-96-centos7      PostgreSQL is an advanced Object-Relational …   45                   
kinogmt/centos-ssh                CentOS with SSH                                 29                   [OK]
guyton/centos6                    From official centos6 container with full up…   10                   [OK]
nathonfowlie/centos-jre           Latest CentOS image with the JRE pre-install…   8                    [OK]
centos/tools                      Docker image that has systems administration…   7                    [OK]
centos/redis                      Redis built for CentOS                          6                    [OK]
drecom/centos-ruby                centos ruby                                     6                    [OK]
roboxes/centos8                   A generic CentOS 8 base image.                  4                    
mamohr/centos-java                Oracle Java 8 Docker image based on Centos 7    4                    [OK]
darksheer/centos                  Base Centos Image -- Updated hourly             3                    [OK]
miko2u/centos6                    CentOS6 日本語環境                                   2                    [OK]
amd64/centos                      The official build of CentOS.                   2                    
dokken/centos-7                   CentOS 7 image for kitchen-dokken               2                    
mcnaughton/centos-base            centos base image                               1                    [OK]
blacklabelops/centos              CentOS Base Image! Built and Updates Daily!     1                    [OK]
starlabio/centos-native-build     Our CentOS image for native builds              0                    [OK]
smartentry/centos                 centos with smartentry                          0                    [OK]

删除镜像

docker image rm [镜像名]/[镜像id]
docker image rm centos
docker image rm 5d0da3dc9764

保存镜像

保存一个或多个镜像到一个tar归档文件

docker image save 镜像名 -o xxx.tar

加载镜像

从tar归档或者标准输入来加载镜像

docker image load 镜像名 -i xxx.tar

推送

以打包自己的镜像,然后推送到仓库,需要注册一个docker hub的账号,可

docker push 镜像名

构造镜像

从Dockerfile构造一个镜像

docker build -t name:tag path
举报

相关推荐

0 条评论