基于alpine鏡像制作
準(zhǔn)備源文件
[root@localhost alpine]# ls
Dockerfile nginx-1.16.1.tar.gz repositories
[root@localhost alpine]# cat repositories
http://mirrors.aliyun.com/alpine/v3.11/main
http://mirrors.aliyun.com/alpine/v3.11/community
dockerfile內(nèi)容
#dockerfile nginx is image
FROM alpine:3.11
LABEL mail=timerovers@163.com
ENV NGINX_VERSION nginx-1.16.1
COPY repositories /etc/apk/repositories
#安裝依賴(lài)
RUN apk add --no-cache autoconf gcc make automake libgcc libc-dev libcurl libc-utils pcre pcre-dev zlib \
zlib-dev openssl openssl-dev libxml2 libxml2-dev libxslt-dev gd-dev perl-dev \
libnfs libevent libevent-dev iproute2 geoip-dev ca-certificates gnupg linux-headers \
&& apk add -U tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/shanghai" >> /etc/timezone
#將nginx.tar.gz解壓到鏡像內(nèi)
ADD ${NGINX_VERSION}.tar.gz /usr/local/src/
#創(chuàng)建nginx用戶(hù)
#RUN addgroup -g 2001 -S nginx && adduser -s /sbin/nolongin -S -D -u 2001 -G nginx nginx
#編譯安裝
RUN cd /usr/local/src/${NGINX_VERSION} \
&& ./configure --prefix=/usr/local/nginx \
--with-http_ssl_module --with-http_v2_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 && rm -rf /usr/local/src/${NGINX_VERSION} && rm -rf /var/cache/apk/* \
&& ln -sv /usr/local/nginx/sbin/nginx /usr/bin/ \
&& chown -R nginx:nginx /usr/local/nginx/
EXPOSE 80
EXPOSE 443
WORKDIR /usr/local/nginx/
CMD ["sbin/nginx","-g","daemon off;"]
查看大小
[root@localhost alpine]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-base 1.16.1 699b9fa70217 3 minutes ago 280MB
基于ubuntu鏡像制作
準(zhǔn)備文件以及apt源
[root@localhost ubuntu]# ls
Dockerfile nginx-1.16.1.tar.gz sources.list
[root@localhost ubuntu]# cat sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
dockerfile內(nèi)容
[root@localhost ubuntu]# cat Dockerfile
#dockerfile nginx is image
FROM ubuntu:18.04
LABEL mail=timerovers@163.com
ENV NGINX_VERSION nginx-1.16.1
#apt源
COPY sources.list /etc/apt/sources.list
#安裝依賴(lài)
RUN apt update \
&& apt -y install tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& apt install -y language-pack-zh-hans \
&& apt -y install gcc g++ make unzip bzip2 zlib1g zlib1g-dev \
libpcre3 libpcre3-dev openssl \
libssl-dev libgeoip1 libgeoip-dev libgeoip-dev \
libtool build-essential libgd-dev \
&& apt-get clean
#將nginx.tar.gz解壓到鏡像內(nèi)
ADD $NGINX_VERSION.tar.gz /usr/local/src/
#創(chuàng)建nginx用戶(hù)
RUN groupadd -g 2001 nginx && useradd -s /sbin/nolongin -g nginx -u 2001 nginx
#編譯安裝
RUN cd /usr/local/src/$NGINX_VERSION \
&& ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_geoip_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_image_filter_module \
--with-http_addition_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_slice_module \
--with-http_stub_status_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit \
--with-debug \
&& make && make install && rm -rf /usr/local/src/$NGINX_VERSION \
&& ln -sv /usr/local/nginx/sbin/nginx /usr/bin/ \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/cache/apk/*
EXPOSE 80
EXPOSE 443
WORKDIR /usr/local/nginx/
CMD ["sbin/nginx","-g","daemon off;"]
查看大小
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-ubuntu 1.16.1 0095df4127e1 7 minutes ago 486MB
最后編輯于 :2022.09.11 11:42:51
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者