docker学习(1) — 编译nginx镜像

docker 是个好东西啊,解决了不同环境下部署的问题


FROM centos
ENV NGINX_VERSION 1.15.9
ENV buildOps 'gcc gcc-c++ autoconf automake make wget vim openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed libtool zlib zlib-devel pcre pcre-devel patch'
RUN yum update -y \
&& yum install -y $buildOps \
&& mkdir /root/nginx \
&& mkdir -p /conf/nginx/ \
&& mkdir -p /var/log/nginx/ \
&& mkdir -p /cgis/fcgi/ \
&& mkdir -p /cgis/uwsgi/ \
&& mkdir -p /cgis/scgi/ \
&& mkdir -p /var/tmp/nginx/client/ \
&& mkdir -p /var/tmp/nginx/proxy/ \
&& cd /root/nginx \
&& wget -O nginx.tar.gz https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
&& tar -zvxf nginx.tar.gz -C ../nginx \
&& cd nginx-${NGINX_VERSION} \
&& ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--conf-path=/conf/nginx/nginx.conf \
--http-fastcgi-temp-path=/cgis/fcgi/ \
--http-uwsgi-temp-path=/cgis/uwsgi/ \
--http-scgi-temp-path=/cgis/scgi/ \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_random_index_module \
--with-http_degradation_module \
--with-http_secure_link_module \
--with-http_gzip_static_module \
--with-http_perl_module \
--with-file-aio \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-ld-opt="-Wl,-E" \
&& make && make install \
&& cd /root \
&& rm -rf ./nginx \
&& echo 'daemon off;' >> /conf/nginx/nginx.conf \
&& echo 'master_process off;' >> /conf/nginx/nginx.conf \
&& echo '

Hello, Docker!

' > /usr/local/nginx/html/index.html
ENTRYPOINT ["/usr/sbin/nginx"]

docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
531f80595130 1e1148e4cc2c “/bin/sh -c ‘buildOp…” 8 minutes ago Exited (1) 3 minutes ago recursing_kalam

docker commit –author “username ” –message “信息” CONTAINER ID 容器名
如 docker commit –author “hanasakari ” –message “第一次编译” 531f80595130 nginx:v1

sudo docker run –name web -p 80:80 nginx:v1