镜像的基本操作

1、搜索官方仓库的镜像

使用#docker search命令

[root@localhost ~]# docker search --help

Usage:  docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
  -f, --filter filter   Filter output based on conditions provided
      --help            Print usage
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
[root@localhost ~]# docker search nginx
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                             Official build of Nginx.                        15262     [OK]
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker c...   2054                 [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable ...   815                  [OK]

NAME:镜像名称

DESCRIPTION:镜像说明

STARS:点赞数量

OFFICIAL:是否是官方

AUTOMATED:是否是自动构建的

 镜像的操作包括一下内容

[root@localhost ~]# docker image --help

Usage:  docker image COMMAND

Manage images

Options:
      --help   Print usage

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.

2、拉取镜像

(1)根据镜像名称(tag指定版本)拉取镜像

[root@localhost ~]# docker pull --help

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --help                    Print usage
[root@localhost~]# docker pull nginx:1.14-alpine
1.14-alpine: Pulling from library/nginx
cd784148e348: Pull complete
12b08f7ef616: Pull complete
65071a4e699c: Pull complete
9936647427be: Pull complete
Digest: sha256:e3f77f7f4a6bb5e7820e013fa60b96602b34f5704e796cfd94b561ae73adcf96
Status: Downloaded newer image for nginx:1.14-alpine

# alpine 版本:构建容器小镜像的发型版本

[root@localhost ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
b4a6e23922dd: Pull complete
Digest: sha256:8ccbac733d19c0dd4d70b4f0c1e12245b5fa3ad24758a11035ee505c629c0796
Status: Downloaded newer image for busybox:latest

(2)查看当前主机镜像列表

[root@localhost ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              69593048aa3a        8 weeks ago         1.24 MB
nginx               1.14-alpine         8a2fb25a19f5        2 years ago         16 MB


3、导出镜像

方法一:

[root@localhost ~]# docker image save busybox > docker-busybox.tar.gz
[root@localhost ~]# ls docker-busybox.tar.gz
docker-busybox.tar.gz

方法二:一次可以导出多个镜像

[root@localhost ~]# docker image save -o /mnt/busybox.tar.gz busybox:latest nginx:1.14-alpine
[root@localhost ~]# ls /mnt/busybox.tar.gz
/mnt/busybox.tar.gz

-o:指定到处镜像的位置

指定.tar.gz可以导出并压缩

4、删除镜像

[root@localhost ~]# docker image rm busybox
Untagged: busybox:latest
Untagged: busybox@sha256:0f354ec1728d9ff32edcd7d1b8bbdfc798277ad36120dc3dc683be44524c8b60
Deleted: sha256:69593048aa3acfee0f75f20b77acb549de2472063053f6730c4091b53f2dfb02
Deleted: sha256:5b8c72934dfc08c7d2bd707e93197550f06c0751023dabb3a045b723c5e7b373
[root@localhost ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.14-alpine         8a2fb25a19f5        2 years ago         16 MB

5、导入镜像

[root@localhost ~]# docker image load -i docker-busybox.tar.gz
5b8c72934dfc: Loading layer 1.455 MB/1.455 MB
Loaded image: busybox:latest
[root@localhost ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              69593048aa3a        8 weeks ago         1.24 MB
nginx               1.14-alpine         8a2fb25a19f5        2 years ago         16 MB

6、查看镜像的详细信息

[root@localhost ~]# docker image  inspect busybox
[
    {
        "Id": "sha256:69593048aa3acfee0f75f20b77acb549de2472063053f6730c4091b53f2dfb02",
        "RepoTags": [
            "busybox:latest"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "",
        "Created": "2021-06-07T20:20:29.305375985Z",
        "Container": "6dd2b340ed3c81fb1f73ff1c7cfa6fde88cf6dd4b0d35f2e7045f2c93ca71481",
        "ContainerConfig": {
            "Hostname": "6dd2b340ed3c",
            "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 [\"sh\"]"
            ],
            "Image": "sha256:34dd1172b5b26c557e72a400b1c9aaf26746efe34ce01023f605cdb4d5870ad3",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "19.03.12",
        "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": [
                "sh"
            ],
            "Image": "sha256:34dd1172b5b26c557e72a400b1c9aaf26746efe34ce01023f605cdb4d5870ad3",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 1235821,
        "VirtualSize": 1235821,
        "GraphDriver": {
            "Name": "overlay",
            "Data": {
                "RootDir": "/var/lib/docker/overlay/36903fb43a86d338723dec6792c1880f37c087a81c96856057cc2eb791e3604a/root"
            }
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:5b8c72934dfc08c7d2bd707e93197550f06c0751023dabb3a045b723c5e7b373"
            ]
        }
    }
]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值