Dockerfile构建NGINX镜像

使用了CENTOS的基础镜像

[[email protected] b3]# ls
Dockerfile  nginx-1.8.0.tar.gz


[[email protected] b3]# cat Dockerfile 
FROM centos
MAINTAINER [email protected]
ADD nginx-1.8.0.tar.gz /usr/local/src
WORKDIR /usr/local/src/nginx-1.8.0
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel \
&& useradd -M -s /sbin/nologin nginx \
&& ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
EXPOSE 80

构建过程:

[[email protected] b3]# docker build -t centosng:v1 .
Sending build context to Docker daemon 835.6 kB
Step 1/6 : FROM centos
 ---> 1e1148e4cc2c
Step 2/6 : MAINTAINER [email protected]
 ---> Running in 75d30b772be7
 ---> 103ea4e7ee16
Removing intermediate container 75d30b772be7
Step 3/6 : ADD nginx-1.8.0.tar.gz /usr/local/src
 ---> ff372fbff498
Removing intermediate container 53e17ebfd2ba
Step 4/6 : WORKDIR /usr/local/src/nginx-1.8.0
 ---> 9192a1041d87
Removing intermediate container 3371e3be43f6
Step 5/6 : RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel && useradd -M -s /sbin/nologin nginx && ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
 ---> Running in 37f83f076d5f

Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.163.com
Package glibc-2.17-260.el7.x86_64 already installed and latest version
Package pcre-8.32-17.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-13.el7 will be installed
---> Package GeoIP-devel.x86_64 0:1.5.0-13.el7 will be installed

 

建构完成后启动容器,映射主机的80端口

[[email protected] b3]# docker run -d -p80:80 centosng:v1 /usr/local/nginx/sbin/nginx -g "daemon off;"
d8d5a8a52bc6f07172849349580ee675729be2a0727b6c5b5c1df7ca4aa8694a
[[email protected] b3]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                NAMES
d8d5a8a52bc6        centosng:v1         "/usr/local/nginx/..."   21 seconds ago      Up 20 seconds               0.0.0.0:80->80/tcp   wizardly_babbage

 

访问:

Dockerfile构建NGINX镜像