docker Learning - Mirror

For docker users, the best-case scenario is not required to create their own image, mirrored almost all the common database, middleware, and application software are ready docker official mirror or other people and organizations to create, we only need to slightly configuration can be used directly.
However, in some cases, also need to build their own image.
For example:
1, can not find ready-made image, develop their own applications such as
2, need to add specific functionality in the mirror.
docker provides two ways to build mirror: docker commit command and Dockerfile build file.

docker commit

docker commit command formula create a mirror of the most intuitive way, the process comprising three steps
1, run the container
2, to modify the container
3, the storage container as a new image
, such as: mounting vi in Ubuntu base image and save it as a new image
(1 ) run vessel
docker Learning - Mirror
acting -it parameters into the container in the interactive mode, and open a terminal.
2b1763cc8299 is inside the container ID
(2) is mounted vim
acknowledgment is not installed vim
docker Learning - Mirror
installed vim, as follows:
docker Learning - Mirror
(3) Save the new image
view of the container currently running in a new window
docker Learning - Mirror
distracter_chaum Docker our container is randomly assigned the name of
execution docker commit command to save the vessel to mirror
docker Learning - Mirror
the new image named ubuntu-with-vim
see the new image of the property as follows:
docker Learning - Mirror
you can see the new image because the software is installed vim and bigger
from the new mirrored boot container, can already verify vim use
docker Learning - Mirror

虽然我们可以使用docker commit创建新镜像,但是docker不建议用户使用这种方式构建镜像。原因如下:
1、该方式是手工创建镜像的方式了,容易出错,效率低可重复性弱
2、无法对镜像进行审计,存在安全隐患

Dockerfile

Dockerfile是一个文本文件,记录了镜像构建的所有步骤

第一个Dockerfile

新建一个文本文件Dockerfile,内容如下:
docker Learning - Mirror
以下为运行docker build命令构建镜像并详细分析细节

[root@docker-1 ~]# docker build -t ubuntu-with-vim-dockerfile .    (1)
Sending build context to Docker daemon  13.31kB                        (2)
Step 1/2 : FROM ubuntu                                                                  (3)
 ---> a2a15febcdf3
Step 2/2 : RUN apt-get update && apt-get install -y vim                   (4)
 ---> Running in ad7fa94cfb94                                                           (5)
Successfully built ad7fa94cfb94                                                         (6)
Successfully tagged ubuntu-with-vim-dockerfile:latest                              (7)

Description:
1, run docker build command, -t new image will be named at the end-vim-dockerfile ubuntu-with command indicates build context for the current directory. Find Dockerfile Docker default file from the build context,
can also be specified by the file location Dockerfile -f argument
2, mirror-configuration process. Docker first transmitting files to build context Docker daemon, bulid context or object constructed to provide the required image. The Dockerfile ADD, COPY command to add file to build context mirror, in this embodiment, bulid context .Root the current directory, all files and subdirectories in the directory will be sent to Docker daemon. Be careful not to put unnecessary files bulid context, in particular, do not put /, / usr as bulid context, otherwise the build process will be very slow or even fail
3, Step1, execute FROM, Ubuntu as a base to Mirror the ID is a2a15febcdf3
4, step2, perform the RUN, the installation vim
. 5, start temporary container, in a container apt-get install vim through
6, after the installation is complete, save the container is a mirror whose ID is ad7fa94cfb94
step underlayer using similar docker commit command
7, mirror Construction of success

View image information docker images

docker Learning - Mirror

Guess you like

Origin blog.51cto.com/11555417/2436919