This chapter explains more about image, including:
Fetching an image from the warehouse;
command:
docker pull [options] [Docker Registry address [: Port Number] /] warehouse name [: label] # The default is to pull the mirror dockerhub
For example: mirroring pulling nginx
[root@localhost ~]# docker pull nginx
Management mirrored on the local host:
1. List the mirror
docker image ls
The list contains the warehouse name , tag , image ID , creation time and space occupied .
2. Check the mirror up hard disk size
3. List a mirror
[root@localhost ~]# docker image ls nginx
4. The image displayed in a specific format
5. Delete the local mirror
Command: $ docker image rm [option] <mirror 1> [<Mirror 2> ...]
docker image rm ID
docker image rm image name
Use docker image ls to cope delete
For example: delete called a mirror image of redis
docker image rm $ (docker image ls -q redis) # -q parameter display image id
For example: Delete redis: 2.2 before the mirror
docker image rm $(docker image ls -q -f before=redis:2.2)
For example: remove all mirrors
docker image rm $(docker image ls -q )
6. Modify the files in the container to see what changed: You can use docker diff command
docker diff results show three states
A
Adding a file or directory
B
File or directory is deleted
C
From the original
7.docker commit mirrored storage container, generally used to retain the site, and the virtual machine snapshot feature is quite similar
docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]]
其中 --author 是指定修改的作者,而 --message 则是记录本次修改的内容。这点和 git
版本控制相似,不过这里这些信息可以省略留空。
8.Dockerfile制作镜像
Dockerfile 是一个文本文件,其内包含了一条条的指令,每一条指令构建一层,因此每一条指令的内容
FROM:
使用docker制作镜像的时候大部分情况下需要在原有的镜像基础上进行部署,当然也有不需要基于基础镜像的
的情况,例如swarm、coreos、etcd.
需要制定基础的镜像的时候可以使用下面命令
#以nginx镜像作为基础镜像进行操作,默认nginx会到dockerhub上下载
FROM nginx
#不以任何镜像为基础镜像可以使用
FROM scratch
RUN:
RUN 指令是用来执行命令行命令的。由于命令行的强大能力, RUN 指令在定制镜像时是最
常用的指令之一。其格式有两种:
1.shell 格式: RUN <命令>
RUN echo "Hello Docker" > /usr/share/nginx/index/index.html
2.exec 格式: RUN ["可执行文件", "参数1", "参数2"]
RUN ["/bin/bash","-c","echo hello"]
介绍镜像实现的基本原理: