利用Dockerfile构建一个nginx容器
1.从远程仓库中pull centos镜像
docker pull centos
2.查询镜像
docker images
3.下载nginx和pcre到本地目录下
4.编辑Dockerfile文件
#Nginx dockerfile
#Version 1.0
#Author: kehaojian
#Base images
FROM centos
#MAINTAINER 维护人
MAINTAINER kehaojian
#ADD 添加本地文件到镜像
ADD pcre-8.37.tar.gz /usr/local/src
ADD nginx-1.9.3.tar.gz /usr/local/src
#RUN 在镜像中执行命令
RUN yum install -y wget gcc_c++ make openssl-devel
RUN useradd -s /sbin/nologin -M www
#WORKDIR 镜像中切换到目录
WORKDIR /usr/local/src/nginx-1.9.3
RUN yum install -y gcc gcc-c++
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37 && make && make install
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
#配置环境变量
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
#命令
CMD ["nginx"]
5.执行构造命令 docker build -t nginx-docker:v1 .
[root@HA2 src]# docker build -t nginx-docker:v1 .
Sending build context to Docker daemon 8.234 MB
Step 1 : FROM centos
---> 3fa822599e10
Step 2 : MAINTAINER kehaojian
---> Using cache
---> 7a13a2573c2c
Step 3 : ADD pcre-8.37.tar.gz /usr/local/src
---> Using cache
---> 27f018c7c6c2
Step 4 : ADD nginx-1.9.3.tar.gz /usr/local/src
---> Using cache
---> 0ac134999174
Step 5 : RUN yum install -y wget gcc_c++ make openssl-devel
---> Using cache
---> 2caeaffce308
Step 6 : RUN useradd -s /sbin/nologin -M www
---> Using cache
---> 50fad5×××87
Step 7 : WORKDIR /usr/local/src/nginx-1.9.3
---> Using cache
---> c223ad0c0e56
Step 8 : RUN yum install -y gcc gcc-c++
---> Using cache
---> 535006fabee5
Step 9 : RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37 && make && make install
---> Using cache
---> 2c8bfa5d7162
Step 10 : RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
---> Using cache
---> 3ab469fa6de1
Step 11 : ENV PATH /usr/local/nginx/sbin:$PATH
---> Using cache
---> 399e3d091604
Step 12 : EXPOSE 80
---> Using cache
---> 0e84b1ddfd98
Step 13 : CMD nginx
---> Using cache
---> 20c4d11561d3
Successfully built 20c4d11561d3
6.查看镜像 docker images
7.启动容器 docker run -it -d -p 8888:80 --name nginx8888 20c4d11561d3
8.查看容器 docker ps -l
9.访问http://ha2:8888