Dockerfile1:httpd:0.1
vim Dockerfile
#Version: 0.1
FROM centos
Run yum -y install httpd
RUN echo "Hello world!" > /var/www/html/index.html
EXPOSE 80
docker build -t fcj/httpd:0.1 .
docker run -it --name httpd fcj/httpd:0.1
httpd -k start
curl http://127.0.0.1/
docker push fcj/httpd:0.1
Dockerfile1:httpd:0.2
vim Dockerfile
#Version: 0.2
FROM centos
Run yum -y install httpd
RUN echo "Hello world!" > /var/www/html/index.html
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
EXPOSE 80
docker build -t fcj/httpd:0.2 .
docker run -d -p 80:80 --name httpd fcj/httpd:0.2
curl http://localhost/
Dockerfile1:httpd:0.3
vim Dockerfile
#Version: 0.3
FROM centos
Run yum -y install httpd
RUN echo "Hello world!" > /var/www/html/index.html
#CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
EXPOSE 80
docker build -t fcj/httpd:0.3 .
docker run -d -p 80:80 --name httpd fcj/httpd:0.3 -D FOREGROUND
curl http://localhost/
RUN\CMD\ENTRYPOINT
RUN:构建时执行
CMD:容器启动时执行,docker run后参数会覆盖CMD
ENTRYPOINT:容器启动时执行,docker run后参数会附加至ENTRYPOINT
Dockerfile1:test:0.1
vim Dockerfile
FROM centos
WORKDIR /tmp
docker build -t fcj/test .
docker run -it fcj/test pwd
docker run -it fcj/test /bin/bash
WORKDIR:切换工作目录
Dockerfile1:test:0.2
vim Dockerfile
FROM centos
ENV TARGET_DIR /opt
WORKDIR $TARGET_DIR
docker build -t fcj/test .
docker run -it fcj/test /bin/bash
docker run -it -e "MYSQL_PORT=3307" fcj/test /bin/bash
ENV:定义环境变量
-e:命令行指定环境变量
Dockerfile1:test:0.3
touch test01 test02 test03 test04
tar -zcvf test02.tgz test02
tar -zcvf test04.tgz test04
vim Dockerfile
FROM centos
ADD test01 /opt/
ADD test02.tgz /opt/
COPY test03 /opt/
COPY test04.tgz /opt/
docker build -t fcj/test .
docker run -it fcj/test /bin/bash
ADD:可以解压缩
COPY:无解压缩
Dockerfile1:test:0.4
vim Dockerfile
FROM centos
VOLUME ["/data"]
docker build -t fcj/test .
docker run -it fcj/test /bin/bash
VOLUME:添加挂载点