vim Dockerfile //内容如下
## Set the base image to CentOS
FROM centos
# File Author / Maintainer
MAINTAINER xavi XXX@xxxx.com
# Install necessary tools
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
# Install Nginx
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar zxvf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install
RUN rm -fv /usr/local/nginx/conf/nginx.conf
ADD http://www.apelearn.com/study_v2/.nginx_conf /usr/local/nginx/conf/nginx.conf
# Expose ports
EXPOSE 80
# Set the default command to execute when creating a new container
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
详解如下:
## Set the base image to CentOS
FROM centos //docker images 出现的镜像
# File Author / Maintainer
MAINTAINER xavi XXX@xxxx.com //指定用户信息
# Install necessary tools
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel //安装必须的插件
# Install Nginx
ADD http://nginx.org/download/nginx-1.8.0.tar.gz . //下载nginx的源码包到本地当前目录
RUN tar zxvf nginx-1.8.0.tar.gz //解压
RUN mkdir -p /usr/local/nginx //级联创建nginx目录
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install //进入目录编译并安装
RUN rm -fv /usr/local/nginx/conf/nginx.conf //删除原配置文件
ADD http://www.apelearn.com/study_v2/.nginx_conf /usr/local/nginx/conf/nginx.conf //下载配置好的nginx配置文件到指定目录
# Expose ports
EXPOSE 80 //映射出去的端口
# Set the default command to execute when creating a new container
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd //设置开机启动的命令(有仔细的朋友可能已经发现 为什么需要 tail -f 呢?其实很多人认为这是一个bug 如果你不添加这个当执行完他就会退出) 2.2 开始创建镜像(同时开启一个docker镜像服务)
//名字一定要命名为 Dockerfile 不然docker build是找不到文件的,-t 指定容器的名字(不可以出现大写字母), 后面的 . 指定去哪儿找Dockerfile