1.docker镜像使用
列出镜像
[root@qicheng /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 15.10 a454816bdf34 2 minutes ago 0B ubuntu latest d70eaf7277ea 4 weeks ago 72.9MB hello-world latest bf756fb1ae65 10 months ago 13.3kB ubuntu <none> 9b9cb95443b5 4 years ago 137MB
各个选项说明:
-
REPOSITORY:表示镜像的仓库源
-
TAG:镜像的标签
-
IMAGE ID:镜像ID
-
CREATED:镜像创建时间
-
SIZE:镜像大小
同一仓库源可以有多个 TAG,代表这个仓库源的不同个版本,如 ubuntu 仓库源里,有 15.10、14.04 等多个不同的版本,我们使用 REPOSITORY:TAG 来定义不同的镜像。
运行指定版本的系统镜像的容器,不指定默认使用 ubuntu:latest 镜像。
2.下载镜像
[root@qicheng /]# docker pull ubuntu:13.10 13.10: Pulling from library/ubuntu Image docker.io/library/ubuntu:13.10 uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/ a3ed95caeb02: Pull complete 0d8710fc57fd: Pull complete 5037c5cd623d: Pull complete 83b53423b49f: Pull complete e9e8bd3b94ab: Pull complete 7db00e6b6e5e: Pull complete Digest: sha256:403105e61e2d540187da20d837b6a6e92efc3eb4337da9c04c191fb5e28c44dc Status: Downloaded newer image for ubuntu:13.10 docker.io/library/ubuntu:13.10
3.查找镜像
NAME: 镜像仓库源的名称
DESCRIPTION: 镜像的描述
OFFICIAL: 是否 docker 官方发布
stars: 类似 Github 里面的 star,表示点赞、喜欢的意思。
AUTOMATED: 自动构建。
4.删除镜像
[root@qicheng /]# docker rmi hello-world Untagged: hello-world:latest Untagged: hello-world@sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323 Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
5.创建镜像
当docker的镜像不满足我们的需求,可以通过如下两种方式对镜像进行修改
- 1、从已经创建的容器中更新镜像,并且提交这个镜像
- 2、使用 Dockerfile 指令来创建一个新的镜像
容器内使用 apt-get update
[root@qicheng /]# docker run -it ubuntu /bin/bash root@54b06b424b2a:/# apt-get update Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB] Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB] Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:4 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [1165 B] Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Get:6 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [643 kB] Get:7 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB] Get:8 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB] Get:9 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [89.4 kB] Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [465 kB] Get:11 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB] Get:12 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB] Get:13 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [126 kB] Get:14 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [849 kB] Get:15 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [869 kB] Get:16 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [30.4 kB] Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [5880 B] Fetched 16.5 MB in 9s (1783 kB/s) Reading package lists... Done