The parameters Dockerfile
# ############ 主要用来构建镜像
FROM # 指定镜像(必须有)
MAINTAINER # 声明维护者(可有可无;位置无所谓,放在FROM后比较合理)
USER # 设置容器运行的UID(可有可无)
ENV # 指定环境变量(后续命令可以直接引用“$envname”)
RUN # 执行shell命令,用于创建容器(一般地,每条RUN对应一条命令;也可以利用 `;\`来执行多条命令)
# ############ 主要是用于构建镜像后的部署过程
COPY # 复制宿主机的文件到容器内
ADD # 添加宿主机的文件`或者URL`到容器内(和COPY基本相同,区别多了个下载网络文件)
VOLUME # 将容器内的目录映射到宿主机内(方便在宿主机内查看文件,比如日志,项目源码等)
WORKDIR # 工作目录,指明`CMD命令的运行目录`
ENTRYPOINT # `只能有一个entrypoint存在,不可被docker run 命令的命令行参数覆盖`
EXPOSE # 容器暴露的端口
CMD # 执行shell命令,`和RUN区别`:run用于部署,cmd用于部署运行,并且可以和entrypoint配合使用
Dockerfile some parameters may be covered with command line arguments
When we allow the deployment of dynamic input parameters, specify the parameters covered Dockefile
Specific examples of construction使用场景:2.
scenes to be used
1. Build docker image provided to other persons
Commonly used commands: docker build -t image_name:iamge_tag -f path/Dockerfile --rm ./app
2. The other person under docker image deployment project
Common Command: docker run -d -e -v -u -w -p image_name
Description: -d: background; -e: the specified environment variable; -v: volume within the container and mapping host directory; -u: UID specified operating container; -w: Specifies workdir; -p: designated port
Explanation
- dockerfile almost always placed in the root directory of the project;
- The project file docker project directory and configuration provided dockerfile provide independent environment constructing a project to deploy;
- In general, we do not need to save
docker image
, because theDockerfile
more easy to store and transfer, and more lightweight, easy to edit, consistent environment; - Sometimes order to more quickly deploy
节省构建的时间
, you can save the image file docker, when running the container line operating parameters can be adjusted simply by command.