Docker(三):使用镜像

镜像是创建Docker容器的基础。

一,获取镜像

命令docker pull [OPTIONS] NAME[:TAG|@DIGEST]从指定的NAME镜像仓库下载标签为TAG的镜像。

  • 如果不显式指定TAG,则默认会选择latest标签
  • OPTIONS中:-a,–all-tags=true|false:是否获取仓库中的所有镜像,默认为否;–disable-content-trust:取消镜像的内容校验,默认为真。
root@DangFuLin:~# docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
f22ccc0b8772: Pulling fs layer                                                                                          3cf8fb62ba5f: Downloading                                                                                               e80c964ece6a: Download complete                                                                                         18.04: Pulling from library/ubuntu
f22ccc0b8772: Pull complete                                                                                             3cf8fb62ba5f: Pull complete                                                                                             e80c964ece6a: Pull complete                                                                                             Digest: sha256:fd25e706f3dea2a5ff705dbc3353cf37f08307798f3e360a13e9385840f73fb3
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
  • docker pull ubuntu:18.04命令相当于docker pull registry.hub.docker.com/ubuntu:18.04命令,即从默认的注册服务器Docker Hub Registry中的ubuntu仓库来下载标记为18.04的镜像。
  • 如果从非官方的仓库下载,则需要在仓库名称前指定完整的仓库地址,例如docker pull hub.c.163.com/public/ubuntu:18.04

下载镜像到本地后,即可随时使用该镜像了,例如利用该镜像创建一个容器:

root@DangFuLin:~# docker run -it ubuntu:18.04 bash
root@233c5bac692d:/# echo "hello world!"
hello world!

二,查看镜像信息

1.使用images命令列出镜像

命令docker imagesdocker image ls可以列出本地主机上已有镜像的基本信息。

root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       18.04     2c047404e52d   3 weeks ago   63.3MB
  • REPOSITORY:来源仓库
  • TAG:标签信息
  • IMAGE ID:镜像ID,唯一标识镜像
  • CREATED:镜像最后的更新时间
  • SIZE:该镜像的逻辑体积大小

完整命令docker images [OPTIONS] [REPOSITORY[:TAG]]
命令中的OPTIONS

  • -a,–all=true|false:列出所有(包括临时文件)镜像文件,默认为否;
  • –digests=true|false:列出镜像的数字摘要值,默认为否;
  • -f,–filter=[]:过滤列出的镜像,如dangling=true只显示没有被使用的镜像;也可指定带有特定标注的镜像等;
  • –format=“TEMPLATE”:控制输出格式,如.ID代表ID信息,.Repository代表仓库信息等;
  • –no-trunc=true|false:对输出结果中太长的部分是否进行截断,如镜像的ID信息,默认为是;
  • -q,–quiet=true|false:仅输出ID信息,默认为否。

2.使用tag命令添加镜像标签

命令docker tag可以给镜像创建别名。

root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    f643c72bc252   3 weeks ago   72.9MB
ubuntu       18.04     2c047404e52d   3 weeks ago   63.3MB

root@DangFuLin:~# docker tag ubuntu:latest myubuntu:latest
root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    f643c72bc252   3 weeks ago   72.9MB
myubuntu     latest    f643c72bc252   3 weeks ago   72.9MB
ubuntu       18.04     2c047404e52d   3 weeks ago   63.3MB

多出来的myubuntu的IMAGE ID与ubuntu的是相同的,它们是同一个文件。

3.使用inspect命令查看详细信息

命令docker inspect可以获取该镜像的详细信息。

root@DangFuLin:~# docker inspect ubuntu:18.04
[
    {
        "Id": "sha256:2c047404e52d7f17bdac4121a13cd844447b74e13063f8cb8f8b314467feed06",
        "RepoTags": [
            "ubuntu:18.04"
        ],
        "RepoDigests": [
            "ubuntu@sha256:fd25e706f3dea2a5ff705dbc3353cf37f08307798f3e360a13e9385840f73fb3"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2020-11-25T22:25:17.102901455Z",
        "Container": "360f37005f8aa084aa4a0de8a51b991a359599a40637783b3ceb0ffbe3a78d71",
        "ContainerConfig": {
            "Hostname": "360f37005f8a",
            "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:344b5f1fe8bc116302d6e8fc9d3bdf85f02c01ac55ec9225972319e54ed46f5a",
            "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": [
                "/bin/bash"
            ],
            "Image": "sha256:344b5f1fe8bc116302d6e8fc9d3bdf85f02c01ac55ec9225972319e54ed46f5a",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 63252300,
        "VirtualSize": 63252300,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/8db0edc7861b538a17e7527bf37e2a9833393600bb4ad10b5d376d809c638748/diff:/var/lib/docker/overlay2/e9c1cddcef62892920c99a1daaf1d7d653f1b87988d4d617cb6880af382547f0/diff",
                "MergedDir": "/var/lib/docker/overlay2/54f1c27e6790b7170f48324263354f058eb56825fbe52a43897fe75b9f046556/merged",
                "UpperDir": "/var/lib/docker/overlay2/54f1c27e6790b7170f48324263354f058eb56825fbe52a43897fe75b9f046556/diff",
                "WorkDir": "/var/lib/docker/overlay2/54f1c27e6790b7170f48324263354f058eb56825fbe52a43897fe75b9f046556/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:b43408d5f11b7b2faf048ae4eb25c296536c571fb2f937b4f1c3883386e93d64",
                "sha256:23135df75b44a66efa9d8dc1a10051768c27bd95388f436eb9553e0eb17211f6",
                "sha256:fe6d8881187d429af3f636c574911690455825998c9f366e985eab646665e711"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

4.使用history命令查看镜像历史

命令docker history列出镜像各层的创建信息。

root@DangFuLin:~# docker history ubuntu:18.04
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
2c047404e52d   3 weeks ago   /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>      3 weeks ago   /bin/sh -c mkdir -p /run/systemd && echo 'do…   7B
<missing>      3 weeks ago   /bin/sh -c [ -z "$(apt-get indextargets)" ]     0B
<missing>      3 weeks ago   /bin/sh -c set -xe   && echo '#!/bin/sh' > /…   745B
<missing>      3 weeks ago   /bin/sh -c #(nop) ADD file:6ef542de9959c3061…   63.3MB

三,搜索镜像

命令docker search [OPTIONS] TERM可以搜索Docker Hub官方仓库中的镜像。
其中OPTIONS:

  • -f,–filter filter:过滤输出内容;
  • –format string:格式化输出内容;
  • –limit int:限制输出结果个数,默认为25个;
  • –no-trunc:不截断输出结果。
root@DangFuLin:~# docker search --filter=is-official=true nginx
NAME      DESCRIPTION                STARS     OFFICIAL   AUTOMATED
nginx     Official build of Nginx.   14163     [OK]

root@DangFuLin:~# docker search --filter=stars=4 tensorflow
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tensorflow/tensorflow            Official Docker images for the machine learn…   1813
jupyter/tensorflow-notebook      Jupyter Notebook Scientific Python Stack w/249
tensorflow/serving               Official images for TensorFlow Serving (http…   103
rocm/tensorflow                  Tensorflow with ROCm backend support            58
xblaster/tensorflow-jupyter      Dockerized Jupyter with tensorflow              54                   [OK]
floydhub/tensorflow              tensorflow                                      26                   [OK]
bitnami/tensorflow-serving       Bitnami Docker Image for TensorFlow Serving     14                   [OK]
opensciencegrid/tensorflow-gpu   TensorFlow GPU set up for OSG                   12
emacski/tensorflow-serving       Project images from https://github.com/emacs…   9
ibmcom/tensorflow-ppc64le        Community supported ppc64le docker images fo…   5
tensorflow/tf_grpc_test_server   Testing server for GRPC-based distributed ru…   4

四,删除和清理镜像

1.使用标签删除镜像

命令docker rmi [OPTIONS] IMAGE [IMAGE...]可以删除镜像。
其中OPTIONS

  • -f,-force:强制删除镜像,即使有容器依赖它;
  • -no-prune:不要清理未带标签的父镜像。

其中[IMAGE...]

  • 为标签或ID

这个命令会先尝试删除所有指向该镜像的标签,然后删除该镜像文件本身。

root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
myubuntu     latest    f643c72bc252   3 weeks ago   72.9MB
ubuntu       latest    f643c72bc252   3 weeks ago   72.9MB
ubuntu       18.04     2c047404e52d   3 weeks ago   63.3MB
root@DangFuLin:~# docker rmi myubuntu:latest
Untagged: myubuntu:latest
root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    f643c72bc252   3 weeks ago   72.9MB
ubuntu       18.04     2c047404e52d   3 weeks ago   63.3MB

如果删除只有一个标签的镜像,会删除这个镜像文件的所有文件层:

root@DangFuLin:~# docker rmi ubuntu:latest
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Deleted: sha256:f643c72bc25212974c16f3348b3a898b1ec1eb13ec1539e10a103e6e217eb2f1
Deleted: sha256:9386795d450ce06c6819c8bc5eff8daa71d47ccb9f9fb8d49fe1ccfb5fb3edbe
Deleted: sha256:3779241fda7b1caf03964626c3503e930f2f19a5ffaba6f4b4ad21fd38df3b6b
Deleted: sha256:bacd3af13903e13a43fe87b6944acd1ff21024132aad6e74b4452d984fb1a99a

当有该镜像创建的容器存在时,镜像文件默认是无法被删除的。

root@DangFuLin:~# docker rmi ubuntu:latest
Error response from daemon: conflict: unable to remove repository reference "ubuntu:latest" (must force) - container d84ced51ceab is using its referenced image f643c72bc252

root@DangFuLin:~# docker ps -a #查看所有容器
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                        PORTS     NAMES
d84ced51ceab   ubuntu         "/bin/bash"   9 minutes ago    Exited (127) 8 minutes ago              peaceful_chatterjee
233c5bac692d   ubuntu:18.04   "bash"        16 minutes ago   Exited (127) 12 minutes ago             modest_hofstadter

虽然可以通过-f参数来强制删除一个存在容器依赖的镜像,但并不推荐。

2.使用镜像ID来删除镜像

针对上面 -f 解决的问题,正确的做法是,先删除依赖该镜像的所有容器,再来删除镜像:

root@DangFuLin:~# docker rm d84ced51ceab
d84ced51ceab
root@DangFuLin:~# docker rmi ubuntu:latest
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Deleted: sha256:f643c72bc25212974c16f3348b3a898b1ec1eb13ec1539e10a103e6e217eb2f1
Deleted: sha256:9386795d450ce06c6819c8bc5eff8daa71d47ccb9f9fb8d49fe1ccfb5fb3edbe
Deleted: sha256:3779241fda7b1caf03964626c3503e930f2f19a5ffaba6f4b4ad21fd38df3b6b
Deleted: sha256:bacd3af13903e13a43fe87b6944acd1ff21024132aad6e74b4452d984fb1a99a

3.清理镜像

命令docker image prune [OPTIONS]自动清理临时的遗留镜像文件层,最后会提示释放的存储空间。
其中OPTIONS

  • -a,-all:删除所有无用镜像,不光是临时镜像;
  • -filter filter:只清理符合给定过滤器的镜像;
  • -f,-force:强制删除镜像,而不进行提示确认。
root@DangFuLin:~# docker image prune -f
Total reclaimed space: 0B

五,创建镜像

1.基于已有容器创建

命令docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
其中OPTIONS

  • -a,–author="":作者信息;
  • -c,–change=[]:提交的时候执行Dockerfile指令,包括CMD|ENTRYPOINT|ENV|EXPOSE|LABEL|ONBUILD|USER|VOLUME|WORKDIR等;
  • -m,–message="":提交消息;
  • -p,–pause=true:提交时暂停容器运行。
root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       18.04     2c047404e52d   3 weeks ago   63.3MB
root@DangFuLin:~# docker run -it ubuntu:18.04 /bin/bash
root@366bed9e2f94:/# touch test
root@366bed9e2f94:/# exit
exit

上面的docker run -it ubuntu:18.04 /bin/bash命令启动了一个镜像,这个容器的ID为366bed9e2f94,并在其中创建一个test空文件,之后退出。

然后我们再将发生了变化的容器用commit命令提交为一个新的镜像:

root@DangFuLin:~# docker commit -m "Added a new empty file: test" -a "xiaolu" 366bed9e2f94 test:0.1
sha256:b833128fee517d867d8dcf36b213543ff1b7b40443aa8a5d6f255ffa73cb4e6f
root@DangFuLin:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
test         0.1       b833128fee51   12 seconds ago   63.3MB
ubuntu       18.04     2c047404e52d   3 weeks ago      63.3MB

新创建镜像的ID为sha256:b833128fee517d867d8dcf36b213543ff1b7b40443aa8a5d6f255ffa73cb4e6f。

2.基于本地模板导入

命令docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]直接从一个操作系统模板文件导入一个镜像。

例如从镜像归档文件my_ubuntu_v3.tar创建镜像,命名为runoob/ubuntu:v4

runoob@runoob:~$ docker import  my_ubuntu_v3.tar runoob/ubuntu:v4  
sha256:63ce4a6d6bc3fabb95dbd6c561404a309b7bdfc4e21c1d59fe9fe4299cbfea39

3.基于Dockerfile创建

基于Dockerfile创建是最常见的方式。
Dockerfile是一个文本文件,利用给定的指令描述基于某个父镜像创建新镜像的过程。

例如使用当前目录的 Dockerfile 创建镜像———基于debian:stretch-slim镜像安装Python3环境,构成一个新的python3镜像:

root@DangFuLin:~# ls -l
total 0
root@DangFuLin:~# mkdir mydf
root@DangFuLin:~# cd mydf
root@DangFuLin:~/mydf# ls -l
total 0

root@DangFuLin:~/mydf# vim dockerfile #编写dockerfile
root@DangFuLin:~/mydf# cat dockerfile
FROM debian:stretch-slim
LABEL version="1.0" maintainer="docker user <docker_user@github>"
RUN apt-get update && \
    apt-get install -y python3 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

root@DangFuLin:~/mydf# docker build -t python:3 .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM debian:stretch-slim
stretch-slim: Pulling from library/debian
e50c3c9ef5a2: Pull complete                                                                                             Digest: sha256:eb436e834ba416c45359aa0709febef17fdea65ab6a8f4db12016aa2fa63be0c
Status: Downloaded newer image for debian:stretch-slim
 ---> b87fae470195
Step 2/3 : LABEL version="1.0" maintainer="docker user <docker_user@github>"
 ---> Running in 1fb0c7f20d76
Removing intermediate container 1fb0c7f20d76
 ---> 15cb601a573f
Step 3/3 : RUN apt-get update &&     apt-get install -y python3 &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*
 ---> Running in 78016434fc0d
Get:1 http://security.debian.org/debian-security stretch/updates InRelease [53.0 kB]
Get:2 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [635 kB]
Ign:3 http://deb.debian.org/debian stretch InRelease
Get:4 http://deb.debian.org/debian stretch-updates InRelease [93.6 kB]
Get:5 http://deb.debian.org/debian stretch Release [118 kB]
Get:6 http://deb.debian.org/debian stretch-updates/main amd64 Packages [2596 B]
Get:7 http://deb.debian.org/debian stretch Release.gpg [2410 B]
Get:8 http://deb.debian.org/debian stretch/main amd64 Packages [7080 kB]
Fetched 7984 kB in 2min 45s (48.1 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  bzip2 dh-python file libexpat1 libmagic-mgc libmagic1 libmpdec2
  libpython3-stdlib libpython3.5-minimal libpython3.5-stdlib libreadline7
  libsqlite3-0 libssl1.1 mime-support python3-minimal python3.5
  python3.5-minimal readline-common xz-utils
Suggested packages:
  bzip2-doc libdpkg-perl python3-doc python3-tk python3-venv python3.5-venv
  python3.5-doc binutils binfmt-support readline-doc
The following NEW packages will be installed:
  bzip2 dh-python file libexpat1 libmagic-mgc libmagic1 libmpdec2
  libpython3-stdlib libpython3.5-minimal libpython3.5-stdlib libreadline7
  libsqlite3-0 libssl1.1 mime-support python3 python3-minimal python3.5
  python3.5-minimal readline-common xz-utils
0 upgraded, 20 newly installed, 0 to remove and 0 not upgraded.
Need to get 7897 kB of archives.
After this operation, 36.7 MB of additional disk space will be used.
Get:1 http://security.debian.org/debian-security stretch/updates/main amd64 libssl1.1 amd64 1.1.0l-1~deb9u2 [1358 kB]
Get:2 http://deb.debian.org/debian stretch/main amd64 libexpat1 amd64 2.2.0-2+deb9u3 [83.7 kB]
Get:3 http://deb.debian.org/debian stretch/main amd64 python3-minimal amd64 3.5.3-1 [35.3 kB]
Get:4 http://deb.debian.org/debian stretch/main amd64 mime-support all 3.60 [36.7 kB]
Get:5 http://deb.debian.org/debian stretch/main amd64 libmpdec2 amd64 2.4.2-1 [85.2 kB]
Get:6 http://deb.debian.org/debian stretch/main amd64 readline-common all 7.0-3 [70.4 kB]
Get:7 http://deb.debian.org/debian stretch/main amd64 libreadline7 amd64 7.0-3 [151 kB]
Get:8 http://deb.debian.org/debian stretch/main amd64 libpython3-stdlib amd64 3.5.3-1 [18.6 kB]
Get:9 http://deb.debian.org/debian stretch/main amd64 dh-python all 2.20170125 [86.8 kB]
Get:10 http://deb.debian.org/debian stretch/main amd64 python3 amd64 3.5.3-1 [21.6 kB]
Get:11 http://deb.debian.org/debian stretch/main amd64 bzip2 amd64 1.0.6-8.1 [47.5 kB]
Get:12 http://deb.debian.org/debian stretch/main amd64 libmagic-mgc amd64 1:5.30-1+deb9u3 [222 kB]
Get:13 http://deb.debian.org/debian stretch/main amd64 libmagic1 amd64 1:5.30-1+deb9u3 [111 kB]
Get:14 http://deb.debian.org/debian stretch/main amd64 file amd64 1:5.30-1+deb9u3 [64.2 kB]
Get:15 http://deb.debian.org/debian stretch/main amd64 xz-utils amd64 5.2.2-1.2+b1 [266 kB]
Get:16 http://security.debian.org/debian-security stretch/updates/main amd64 libpython3.5-minimal amd64 3.5.3-1+deb9u3 [575 kB]
Get:17 http://security.debian.org/debian-security stretch/updates/main amd64 python3.5-minimal amd64 3.5.3-1+deb9u3 [1694 kB]
Get:18 http://security.debian.org/debian-security stretch/updates/main amd64 libsqlite3-0 amd64 3.16.2-5+deb9u3 [574 kB]
Get:19 http://security.debian.org/debian-security stretch/updates/main amd64 libpython3.5-stdlib amd64 3.5.3-1+deb9u3 [2167 kB]
Get:20 http://security.debian.org/debian-security stretch/updates/main amd64 python3.5 amd64 3.5.3-1+deb9u3 [231 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 7897 kB in 2min 18s (56.8 kB/s)
Selecting previously unselected package libssl1.1:amd64.
(Reading database ... 6320 files and directories currently installed.)
Preparing to unpack .../00-libssl1.1_1.1.0l-1~deb9u2_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.0l-1~deb9u2) ...
Selecting previously unselected package libpython3.5-minimal:amd64.
Preparing to unpack .../01-libpython3.5-minimal_3.5.3-1+deb9u3_amd64.deb ...
Unpacking libpython3.5-minimal:amd64 (3.5.3-1+deb9u3) ...
Selecting previously unselected package libexpat1:amd64.
Preparing to unpack .../02-libexpat1_2.2.0-2+deb9u3_amd64.deb ...
Unpacking libexpat1:amd64 (2.2.0-2+deb9u3) ...
Selecting previously unselected package python3.5-minimal.
Preparing to unpack .../03-python3.5-minimal_3.5.3-1+deb9u3_amd64.deb ...
Unpacking python3.5-minimal (3.5.3-1+deb9u3) ...
Selecting previously unselected package python3-minimal.
Preparing to unpack .../04-python3-minimal_3.5.3-1_amd64.deb ...
Unpacking python3-minimal (3.5.3-1) ...
Selecting previously unselected package mime-support.
Preparing to unpack .../05-mime-support_3.60_all.deb ...
Unpacking mime-support (3.60) ...
Selecting previously unselected package libmpdec2:amd64.
Preparing to unpack .../06-libmpdec2_2.4.2-1_amd64.deb ...
Unpacking libmpdec2:amd64 (2.4.2-1) ...
Selecting previously unselected package readline-common.
Preparing to unpack .../07-readline-common_7.0-3_all.deb ...
Unpacking readline-common (7.0-3) ...
Selecting previously unselected package libreadline7:amd64.
Preparing to unpack .../08-libreadline7_7.0-3_amd64.deb ...
Unpacking libreadline7:amd64 (7.0-3) ...
Selecting previously unselected package libsqlite3-0:amd64.
Preparing to unpack .../09-libsqlite3-0_3.16.2-5+deb9u3_amd64.deb ...
Unpacking libsqlite3-0:amd64 (3.16.2-5+deb9u3) ...
Selecting previously unselected package libpython3.5-stdlib:amd64.
Preparing to unpack .../10-libpython3.5-stdlib_3.5.3-1+deb9u3_amd64.deb ...
Unpacking libpython3.5-stdlib:amd64 (3.5.3-1+deb9u3) ...
Selecting previously unselected package python3.5.
Preparing to unpack .../11-python3.5_3.5.3-1+deb9u3_amd64.deb ...
Unpacking python3.5 (3.5.3-1+deb9u3) ...
Selecting previously unselected package libpython3-stdlib:amd64.
Preparing to unpack .../12-libpython3-stdlib_3.5.3-1_amd64.deb ...
Unpacking libpython3-stdlib:amd64 (3.5.3-1) ...
Selecting previously unselected package dh-python.
Preparing to unpack .../13-dh-python_2.20170125_all.deb ...
Unpacking dh-python (2.20170125) ...
Setting up libssl1.1:amd64 (1.1.0l-1~deb9u2) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up libpython3.5-minimal:amd64 (3.5.3-1+deb9u3) ...
Setting up libexpat1:amd64 (2.2.0-2+deb9u3) ...
Setting up python3.5-minimal (3.5.3-1+deb9u3) ...
Setting up python3-minimal (3.5.3-1) ...
Selecting previously unselected package python3.
(Reading database ... 7313 files and directories currently installed.)
Preparing to unpack .../0-python3_3.5.3-1_amd64.deb ...
Unpacking python3 (3.5.3-1) ...
Selecting previously unselected package bzip2.
Preparing to unpack .../1-bzip2_1.0.6-8.1_amd64.deb ...
Unpacking bzip2 (1.0.6-8.1) ...
Selecting previously unselected package libmagic-mgc.
Preparing to unpack .../2-libmagic-mgc_1%3a5.30-1+deb9u3_amd64.deb ...
Unpacking libmagic-mgc (1:5.30-1+deb9u3) ...
Selecting previously unselected package libmagic1:amd64.
Preparing to unpack .../3-libmagic1_1%3a5.30-1+deb9u3_amd64.deb ...
Unpacking libmagic1:amd64 (1:5.30-1+deb9u3) ...
Selecting previously unselected package file.
Preparing to unpack .../4-file_1%3a5.30-1+deb9u3_amd64.deb ...
Unpacking file (1:5.30-1+deb9u3) ...
Selecting previously unselected package xz-utils.
Preparing to unpack .../5-xz-utils_5.2.2-1.2+b1_amd64.deb ...
Unpacking xz-utils (5.2.2-1.2+b1) ...
Setting up readline-common (7.0-3) ...
Setting up mime-support (3.60) ...
Setting up libreadline7:amd64 (7.0-3) ...
Setting up libmagic-mgc (1:5.30-1+deb9u3) ...
Setting up bzip2 (1.0.6-8.1) ...
Setting up libmagic1:amd64 (1:5.30-1+deb9u3) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Setting up xz-utils (5.2.2-1.2+b1) ...
update-alternatives: using /usr/bin/xz to provide /usr/bin/lzma (lzma) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/lzma.1.gz because associated file /usr/share/man/man1/xz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/unlzma.1.gz because associated file /usr/share/man/man1/unxz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcat.1.gz because associated file /usr/share/man/man1/xzcat.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzmore.1.gz because associated file /usr/share/man/man1/xzmore.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzless.1.gz because associated file /usr/share/man/man1/xzless.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzdiff.1.gz because associated file /usr/share/man/man1/xzdiff.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcmp.1.gz because associated file /usr/share/man/man1/xzcmp.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzgrep.1.gz because associated file /usr/share/man/man1/xzgrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzegrep.1.gz because associated file /usr/share/man/man1/xzegrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzfgrep.1.gz because associated file /usr/share/man/man1/xzfgrep.1.gz (of link group lzma) doesn't exist
Setting up libsqlite3-0:amd64 (3.16.2-5+deb9u3) ...
Setting up libmpdec2:amd64 (2.4.2-1) ...
Setting up libpython3.5-stdlib:amd64 (3.5.3-1+deb9u3) ...
Setting up file (1:5.30-1+deb9u3) ...
Setting up python3.5 (3.5.3-1+deb9u3) ...
Setting up libpython3-stdlib:amd64 (3.5.3-1) ...
Setting up dh-python (2.20170125) ...
Setting up python3 (3.5.3-1) ...
running python rtupdate hooks for python3.5...
running python post-rtupdate hooks for python3.5...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Removing intermediate container 78016434fc0d
 ---> d16271847387
Successfully built d16271847387
Successfully tagged python:3
root@DangFuLin:~/mydf# docker images
REPOSITORY   TAG            IMAGE ID       CREATED          SIZE
python       3              d16271847387   36 seconds ago   95.2MB
test         0.1            b833128fee51   17 minutes ago   63.3MB
debian       stretch-slim   b87fae470195   6 days ago       55.3MB
ubuntu       18.04          2c047404e52d   3 weeks ago      63.3MB

六,导出和导入镜像

1.导出镜像

命令docker save [OPTIONS] IMAGE [IMAGE...]导出镜像到本地文件。
其中OPTIONS

  • -o :导出镜像到指定的文件中

例如,导出本地的ubuntu:18.04镜像为文件myubuntu18.04.tar

root@DangFuLin:~/mydf# docker images
REPOSITORY   TAG            IMAGE ID       CREATED          SIZE
python       3              d16271847387   5 minutes ago    95.2MB
test         0.1            b833128fee51   21 minutes ago   63.3MB
debian       stretch-slim   b87fae470195   6 days ago       55.3MB
ubuntu       18.04          2c047404e52d   3 weeks ago      63.3MB
root@DangFuLin:~/mydf# docker save -o myubuntu18.04.tar ubuntu:18.04
root@DangFuLin:~/mydf# ls -l
total 64120
-rw-r--r-- 1 root root      206 Dec 17 10:20 dockerfile
-rw------- 1 root root 65652224 Dec 17 10:32 myubuntu18.04.tar

2.导入镜像

命令docker load [OPTIONS]将镜像文件导入到本地镜像库。
其中OPTIONS

  • –input , -i : 指定导入的文件,代替 STDIN
  • –quiet , -q : 精简输出信息

例如,将之前导出的tar文件再导入到本地镜像库:

root@DangFuLin:~/mydf# docker load -i myubuntu18.04.tar
Loaded image: ubuntu:18.04

七,上传镜像

命令docker push [OPTIONS] NAME[:TAG]上传镜像到仓库,默认上传到Docker Hub官方仓库(需要使用docker login命令登录)。
其中OPTIONS

  • –disable-content-trust :忽略镜像的校验,默认开启
xiaolu@DangFuLin:~$ docker images
REPOSITORY   TAG            IMAGE ID       CREATED          SIZE
python       3              d16271847387   37 minutes ago   95.2MB
test         0.1            b833128fee51   54 minutes ago   63.3MB
debian       stretch-slim   b87fae470195   6 days ago       55.3MB
ubuntu       18.04          2c047404e52d   3 weeks ago      63.3MB

xiaolu@DangFuLin:~$ docker tag python:3 dangfulin/dep_python:3

xiaolu@DangFuLin:~$ docker images
REPOSITORY             TAG            IMAGE ID       CREATED          SIZE
dangfulin/dep_python   3              d16271847387   38 minutes ago   95.2MB
python                 3              d16271847387   38 minutes ago   95.2MB
test                   0.1            b833128fee51   55 minutes ago   63.3MB
debian                 stretch-slim   b87fae470195   6 days ago       55.3MB
ubuntu                 18.04          2c047404e52d   3 weeks ago      63.3MB
xiaolu@DangFuLin:~$ docker push dangfulin/dep_python:3
The push refers to repository [docker.io/dangfulin/dep_python]
a3fb15b84d48: Pushed                                                                                                    e4b1e8d0745b: Pushed                                                                                                    3: digest: sha256:d69f1fefe79345a210f61c9813fb0dbf9bf1aee3b4182a0c071e6a34b60eb3da size: 741

成功push:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值