一、安装docker

二、创建Dockerfile


#创建文件夹
mkdir centos_nginx
cd centos_nginx
vim Dockerfile



#指定使用那个基础镜像
FROM centos
MAINTAINER Dirk.Wang 510423039@qq.com
LABEL Discription="基于centos的nginx镜像" version="1.0"
WORKDIR /usr/local/src
RUN yum install -y wget
RUN wget http://nginx.org/download/nginx-1.8.0.tar.gz
RUN tar -zxvf nginx-1.8.0.tar.gz
WORKDIR nginx-1.8.0
#安装nginx所依赖的包
RUN yum -y install gcc-c++
RUN yum -y install pcre pcre-devel
RUN yum -y install zlib zlib-devel
RUN yum -y install openssl openssl-devel libssl-dev
RUN ./configure
RUN make
RUN make install
EXPOSE 80



docker build -t centos_nginx .


Centos7 docker nginx容器搭建_docker


Centos7 docker nginx容器搭建_centos_02

 Centos7 docker nginx容器搭建_centos_03

三、创建容器


docker run -dit -p 8085:80 centos_nginx


Centos7 docker nginx容器搭建_centos_04

四、进去容器启动nginx


docker attach loving_haibt


  Centos7 docker nginx容器搭建_nginx_05

  Centos7 docker nginx容器搭建_nginx_06

五、开放端口

  Centos7 docker nginx容器搭建_centos_07

  Centos7 docker nginx容器搭建_docker_08