准备工作
1 下载准备好的nginx配置文件
wget http://www.apelearn.com/study_v2/.nginx_conf
2 docker镜像
3 测试容器的网络连通性
我在这个实验时,设置的IP是192.168.1.11,docker build成功;但是启动nginx后,本机和宿主机都可以curl OK,但是windows访问不到,也没有解决。最后重启了windows在解决。
编辑dockerfile
# vim dockerfile
FROM centos
MAINTAINER hiyang [email protected]
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
#RUN yum install -y pcre-devel wget net-tools gcc
#RUN yum install -y zlib zlib-devel make
#RUN yum install -y openssl-devel
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar xf 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 -f /usr/local/nginx/conf/nginx.conf
COPY .nginx_conf /usr/local/nginx/conf/nginx.conf
EXPOSE 80
#ENTRYPOINT /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
创建镜像
docker build -t centos_nginx .
docker images 可以看到我们新建的镜像