Foreword
advantage:
- Save changes to the container, and used again
- Custom Mirror
- Packaging and distribution services in software and operating environment
Command Summary:
By constructing the container
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Constructed by Dockerfile file
docker build
By constructing the container
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
-a
: Default --author = "", is used to specify the author of a mirror, usually fill in the author's name and contact information.-m
: For recording image information constructed,-p
: Since the construction of the container, the container will suspend the running of the parameters can not suspend the running of the vessel.
Examples
# 通过容器构建镜像
$ docker commit -a "yogile" -m "commit test" commit_t yogile/commit_t
sha256:8429b31f250ee3e6ac4f9cef2e209e5e5b0f186bfbe0eb70359886560ccd6e7e
# 查看镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yogile/commit_t latest 8429b31f250e 23 seconds ago 209MB
At this time, we have built a mirror, this mirror can run the container.
Use Dockerfile build file
This method is actually similar to writing a script file and execute it, and then step by step to form a container to be obtained according to the command.
Create a file Dockerfile
Create a directory to store Dockerfile
mkdir -p dockerfile/df_test1
Create a file Dockerfile
vim dockerfile/df_test1/Dockerfile
Here Dockerfile file must be named Dockerfile, otherwise an error:
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/debiana/dockerfile/df_test1/Dockerfile: no such file or directory
Examples
# Dockerfile
# 选择镜像的所需 Repository 仓库
FROM ubuntu:18.04
# 填写维护人员信息
MAINTAINER "Yogile" "[email protected]"
# 执行 apt-get update 命令
RUN apt-get update
# 执行下载安装 nginx 命令
RUN apt-get install nginx -y
# 绑定端口 80
EXPOSE 80
Use docker build
build Mirror
docker build [OPTIONS] PATH | URL | -
-t
: - tag = "", designated to build the image namePATH
: Specifies the path Dockerfile file
Examples
docker build -t ubuntu_yyy dockerfile/df_test1