- 下载需要的安装包
- wget https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz
- wget http://nginx.org/download/nginx-1.14.0.tar.gz
- DockerFile 命令解析
- FROM 它的妈妈是谁(基础镜像)
- MAINTAINER 告诉别人你创造了它(维护者信息)
- RUN 你想让它干嘛(把命令前面加上RUN)
- ADD 往它肚子里面放点文件(COPY文件,会自动解压)
- WORKDIR 我是cd,今天刚化了妆(当前工作目录)
- VOLUME 给我一个存放行礼的地方(目录挂载)
- EXPOSE 我要打开的门是啥(端口)
- CMD 指定启动容器时默认执行的命令
- ENV 指定环境变量,在镜像生成过程中会被后续RUN指令使用,在镜像启动的容器中也会存在
- 创建Dockerfile(名字不能换)
- mkdir Dockerfile
-
# This is My first Dockerfile # Version 1.0 # Author: Xupx #Base image FROM centos #MAINTAINER MAINTAINER Xupx #ADD ADD pcre-8.37.tar.gz /usr/local/src ADD nginx-1.14.0.tar.gz /usr/local/src #RUN RUN yum install -y wget gcc gcc-c++ make openssl-devel RUN useradd -s /sbin/nologin -M www #WORKDIR WORKDIR /usr/local/src/nginx-1.14.0 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"]
-
./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
-
--with-http_realip_module #nginx获取客户端真实IP的模块
-
--with-http_sub_module #用于替换网站页面关键字--平常基本没啥用
-
--with-http_gzip_static_module #静态缓存压缩,用于减少流量
-
--with-http_gunzip_module #为不支持gzip模块的客户端提供解压缩服务,用于节省空间减少IO
-
--with-http_ssl_module #使nginx支持https
-
--with-http_ssl_module #使nginx支持https
-
--with-http_stub_status_module #用于监控nginx状态
-
-
生成镜像
-
docker build -t nginx-file:v1 .
-
-
启动测试
-
docker -d -p 81:80 --name nginx nginx-file:v1
-
-
url访问
-
localhost:81
-
转载于:https://my.oschina.net/xpx/blog/1829203