1.写一个Dockerfile文件
FROM centos
MAINTAINER apeng apeng@apenglinux-002.com
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
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 -j 4 && make -j 4 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 80
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
2.创建新的images为centos:nginx
[root@localhost nginx]# docker build -t centos:nginx .
3.查看镜像
[root@localhost mail]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos nginx f9969a963007 About a minute ago 372MB
lz/centos 6.7 88b1501bda70 About an hour ago 191MB
4.映射容器端口
[root@localhost ~]# docker run -itd -p 80:80 centos:nginx /bin/bash
f52eac063359bfbe8273f8b8bd8965d9325887d020a6d8f0e4314d2e2a2120d7
[root@localhost ~]#
5.在浏览器中访问
如图所示说明安装成功!