FROM scratch #制作base image
FROM centos # 使用base images
FROM ubuntu: 14.04
LABEL maintainer = "jiangpeng@qq.com"
LABEL version = "1.0"
LABEL description = "this is my world"
RUN yum update && yum install -y vim \
python-dev #反斜线换行
RUN apt-get update && apt-get install -y perl \
pwgen --no-install-recommends && rm -rf \
/var/lib/apt/lists/* #注意清理cache
RUN /bin/bash -c 'source $HOME/.bashrc; echo $HOME'
WORKDIR /root
WORKDIR /test #如果没有会自动创建teat目录
WORKDIR demo
RUN pwd #输出结果应该是 /test/demo
ADD hello /
ADD test.tar.gz / #添加到根目录并解压
WORKDIR /root
ADD[/COPY] hello test/ # 此时hello文件所在目录为 /root/test/hello
ENV MYSQL_VERSION 5.6 #设置常量
RUN apt-get install -y mysql-server = "${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* #引用常量
#不管是否指定主机端口,使用ports都会将端口暴露给主机
ports:
// Exec 格式
RUN "apt-get","install","-y","vim"
CMD "/bin/echo","hello docker"
ENTRYPOINT "/bin/echo","hello docker"
// dockerfile1
FROM centos
ENV name Docker
ENTRYPOINT echo "hello $name"
// dockerfile2
FROM centos
ENV name Docker
ENTRYPOINT "/bin/echo" ,"hello $name"
复制代码
dockerfile2中输出的结果为hello $name,如果想要输出hello Docker,则可以dockerfile2中的 "/bin/echo","hello &name" 改为 "/bin/bash","-c","echo hello &name",因为不以bash执行则echo,只是单纯在执行echo则是什么就输出什么,不会解析变量。