DockerFile文件格式
- 2016-12-14 14:51:00
- 村里来的扫地僧 原创
- 3746
1.FROM 指定基于哪个基础镜像 FROM <image>:<tag> 2.MAINTAINER <name> MAINTAINER aming aming@aminglinux.com 3.RUN 镜像操作 RUN <command> 或者 RUN ["executable","param1","param2"] RUN yum install httpd RUN ["/bin/bash","-c","echo htllo"] 4.CMD #只能运行一个,最后一个 CMD 生效 CMD ["executable","param1","param2"] CMD command param1 param2 CMD ["param1","param2"] CMD ["/bin/bash","/usr/local/nginx/sbin/nginx","-c","/usr/local/nginx/conf/nginx.conf"] 5.EXPOSE 指定映射出去的端口 EXPOSE 22 80 8443 -P 自动分配容器的服务端口,-p 指定端口 6.ENV ENV PATH /usr/local/mysql/bin:$PATH 7.ADD 把本地的文件或目录拷贝到容器的某个目录 其中 src 为 Dockerfile 所在的目录的相对路径,也可以是一个 url ADD <conf/vhosts> </usr/local/nginx/conf> 8.COPY 格式同 ADD,区别是不支持 url 9.ENTRYPOINT 类似 CMD 1).CMD 可以被 docker run 覆盖,而ENTRYPOINT 不能被覆盖 docker run .... bash 其中 的 bash 指令会覆盖 CMD 指令 2).ENTRYPOINT 比 CMD 优先级高 ENTRYPOINT ["/bin/bash","/usr/local/nginx/sbin/nginx"] CMD ["-c","/usr/local/nginx/conf/nginx.conf"] 10.VOLUME VOLUME ["/data"] 创建一个可以从本地主机或其他容器挂载的挂载点 11.USER USER root 指定运行容器的用户 12.WORKDIR WORKDIR /path/to/workdir 为RUN,CMD或者 ENTRYPOINT 指定工作目录 [root@localhost dockerfiles]# cat Dockerfile FROM centos:6 MAINTAINER Key Jia <13164952317@126.com> # 单独添加一个文件 ADD files/file1.txt /dir1 ADD files/file2.txt /dir2/ # 添加多个文件 # Step 4 : ADD files/* /dir3 # When using ADD with more than one source file, the destination must be a directory and end with a / # ADD files/* /dir3 ADD files/* /dir4/ # src为文件夹 ADD files /dir5 ADD files /dir6/ ADD files/ /dir7/ # 添加URL文件(带文件名) ADD https://raw.githubusercontent.com/docker/docker/master/Dockerfile /url1 ADD https://raw.githubusercontent.com/docker/docker/master/Dockerfile /url2/ # 添加URL文件(不带文件名) ADD https://github.com/ /url3 # Step 8 : ADD https://github.com/ /url4/ # Downloading 17.63 kB # cannot determine filename from url: https://github.com/ # ADD https://github.com/ /url4/
发表评论