1.通过编写简单的文件自创docker镜像
cd opt && mkdir docker && cd docker
mkdir image1 && cd image1
编写Dockerfile
vim Dockerfile
FROM alpine:latest
MAINTAINER morningcat
CMD echo 'hello docker!'
编译
docker build -t hello-docker .
docker images hello-docker
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-docker latest 1c2ea804e9ae 15 seconds ago 4.15MB
运行
docker run hello-docker
2.实践2
cd /opt/docker && mkdir image2 && cd image2
vim Dockerfile
FROM hub.c.163.com/library/ubuntu
MAINTAINER morningcat
#RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sorces.list
RUN apt-get update
RUN apt-get install -y nginx
COPY index.html /var/www/html
ENTRYPOINT ["/usr/sbin/nginx","-g","daemon off;"]
EXPOSE 80
vim index.html
hello nginx in docker
docker build -t mengzhang6/hello-nginx .
docker run -d -p 80:80 mengzhang6/hello-nginx
访问:http://192.168.140.128/
3.Dockerfile语法
FROM base image
RUN 执行命令
ADD 添加文件
COPY 拷贝文件
CMD 执行命令
EXPOSE 暴露端口
WORKDIR 指定路径
MAINTAINER 维护者
ENV 设定环境变量
ENTRYPOINT 容器入口
USER 指定用户
VOLUME mount point