DockerFile 构建Nginx镜像

FROM centos:latest

# 基准镜像
MAINTAINER "yangxiaonan <https://www.cnblogs.com/2689116388-com/>"

# 作者信息
WORKDIR /usr/local/src/ #工作目录
ENV NG_VERSION nginx-1.16.1 #定义环境变量

RUN yum -y install epel-release #安装epel仓库
RUN yum -y install wget && wget http://nginx.org/download/$NG_VERSION.tar.gz && tar xzvf $NG_VERSION.tar.gz #下载nginx文件并解压

#安装编译依赖包
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel && yum install -y pcre-devel libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
RUN yum clean all #清理仓库
RUN useradd -M -s /sbin/nologin nginx #创建nginx用户
WORKDIR /usr/local/src/$NG_VERSION #切换工作目录

#编译安装nginx
RUN ./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

ADD index.html /usr/local/nginx/html #复制测试页面到容器中
VOLUME /usr/local/nginx/html #设置容器中要挂在到宿主机的目录
ENV PATH /usr/local/nginx/sbin:$PATH #设置sbin环境变量

EXPOSE 80/tcp

#暴露80端口
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]
#当ENTRYPOINT和CMD连用时,CMD的命令是ENTRYPOINT命令的参数,两者连用相当于nginx -g "daemon off;"而当一起连用的时候命令格式最好一致(这里选择的都是
json格式的是成功的,如果都是sh模式可以试一下)

 

事实证明,在语句后面直接跟“#”号写注释,docker build会运行报错的。

注释需要另起一行,“#”后加空格再写注释

 

FROM centos:latest
MAINTAINER "yangxiaonan <https://www.cnblogs.com/2689116388-com/>"
WORKDIR /usr/local/src/
ENV NG_VERSION nginx-1.16.1
RUN yum -y install epel-release
RUN yum -y install wget && wget http://nginx.org/download/$NG_VERSION.tar.gz && tar xzvf $NG_VERSION.tar.gz

RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel && yum install -y pcre-devel libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
RUN yum clean all
RUN useradd -M -s /sbin/nologin nginx
WORKDIR /usr/local/src/$NG_VERSION

RUN ./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
ADD index.html /usr/local/nginx/html
VOLUME /usr/local/nginx/html
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80/tcp
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]

docker build . -t registry/centos8:nginx-1.16.1

docker  build  -f  Dockerfile的名字   仓库名  -t  仓库名:端口/镜像名:标签

docker push 127.0.0.1:5000/nginx:v3

搭建私有镜像仓库,类似私有yum仓库源

client端

vim /etc/docker/daemon.json

{
"insecure-registries": [
"192.168.3.110:5000"
],
"registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"]
}

 

原文链接: https://www.cnblogs.com/2689116388-com/p/12450719.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    DockerFile 构建Nginx镜像

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/334409

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午9:39
下一篇 2023年3月1日 下午9:39

相关推荐