首页 > 其他分享 >使用Dockerfile 制作docker 镜像

使用Dockerfile 制作docker 镜像

时间:2022-12-26 10:24:47浏览次数:40  
标签:http -- RUN module devel nginx 镜像 docker Dockerfile

下面是一个Dockerfile 文件

#基准镜像
FROM centos:7
#作者信息
MAINTAINER "aliyun"
#工作目录
WORKDIR /usr/local/src/ 
#定义环境变量
ENV NG_VERSION nginx-1.21.0 
#安装epel仓库
RUN yum -y install epel-release 
#安装wget
RUN yum -y install wget 
#下载nginx文件并解压
RUN 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 
#创建nginx用户
RUN useradd -M -s /sbin/nologin 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_mo
dule --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_m
odule && make && make install


#设置sbin环境变量
ENV PATH /usr/local/nginx/sbin:$PATH 
#暴露80端口
EXPOSE 80/tcp 
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]
#当ENTRYPOINT和CMD连用时,CMD的命令是ENTRYPOINT命令的参数,两者连用相当于nginx -g "daemon off;"而当一起连用的时候命令格式最好一致(这里选择的都是json格式的是成功的,如果都是sh模式可
以试一下)

也可以使用commit来修改

docker commit nginx-test1 nginx:v3.1

标签:http,--,RUN,module,devel,nginx,镜像,docker,Dockerfile
From: https://www.cnblogs.com/wangcc7/p/17005099.html

相关文章