docker 学习笔记(三)

生成镜像

基于容器生成镜像

修改镜像 tag
[root@test ~]# docker tag --help

Usage:	docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Options:
      --help   Print usage
[root@test ~]# docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/busybox              1.0                 219ee5171f80        3 weeks ago         1.23 MB
  
[root@test ~]# docker tag docker.io/busybox:1.0 docker.io/busybox:latest
[root@test ~]# docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/busybox              1.0                 219ee5171f80        3 weeks ago         1.23 MB
docker.io/busybox              latest              219ee5171f80        3 weeks ago         1.23 MB
基于容器生成镜像
[root@test ~]# docker commit --help
\
Usage:	docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image (default [])
      --help             Print usage
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)
名字,简写默认描述
--author, -a 作者(例如,“John Hannibal Smith hannibal@a-team.com”)
--change, -c 将 Dockerfile 指令应用于创建的映像
--message, -m 提交消息
--pause, -ptrue在提交期间暂停容器

--change 选项将对 Dockerfile 创建的图像应用说明。支持的 Dockerfile 说明:CMD| ENTRYPOINT| ENV| EXPOSE| LABEL| ONBUILD| USER| VOLUME|WORKDIR

[root@test ~]# docker ps -a
CONTAINER ID        IMAGE                                                                           COMMAND                  CREATED             STATUS              PORTS               NAMES
0bda47a24768        docker.io/busybox:latest                                                        "sh"                     18 seconds ago      Up 17 seconds                           busy1
[root@test ~]# docker commit -p busy1 docker.io/busybox:1.1
sha256:96279759b10a9b667967a691016c5df1452546067d13ac4fab91e8cd1c17478b
[root@test ~]# docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/busybox              1.1                 96279759b10a        12 seconds ago      1.23 MB
docker.io/busybox              1.0                 219ee5171f80        3 weeks ago         1.23 MB
docker.io/busybox              latest              219ee5171f80        3 weeks ago         1.23 MB
[root@test ~]# docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" c3f279d17e0a  svendowideit/testimage:version4

f5283438590d

镜像的导出

[root@test ~]# docker save --help

Usage:	docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Options:
      --help            Print usage
  -o, --output string   Write to a file, instead of STDOUT
[root@test ~]# docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/busybox              1.1                 96279759b10a        43 minutes ago      1.23 MB
[root@test ~]# docker save -o busybox1.1.gz docker.io/busybox:1.1
[root@test ~]# ls
anaconda-ks.cfg  busybox1.1.gz

镜像的导入

[root@test ~]# docker load --help

Usage:	docker load [OPTIONS]

Load an image from a tar archive or STDIN

Options:
      --help           Print usage
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output
[root@test ~]# docker load -i busybox1.1.gz
Loaded image: docker.io/busybox:1.1

上一篇 docker 学习笔记(二)
docker 学习笔记目录
下一篇 docker 学习笔记(四)