ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

dockerfile构架镜像(8)

2020-04-01 15:54:09  阅读:279  来源: 互联网

标签:http root myNginx module server nginx 构架 镜像 dockerfile


nginx镜像的构建

先查看下本地的镜像,选取官网的centos作为base image:

[root@server ~]# docker images

创建一个目录专门用来存放的目录,也就是Dockerfile所在的目录

[root@server ~]# mkdir myNginx
[root@server ~]# cd myNginx/
[root@server myNginx]# touch Dockerfile

编写Dockerfile文件的内容,注意该文件名字的首字母要大写。

[root@server myNginx]# cat Dockerfile
# 指定基础镜像
FROM centos

# MAINTAINER
MAINTAINER xxx@qq.com

# 安装基础工具包
RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data

# 下载nginx
ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/

# 解压nginx 并创建用户
RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ \
    && useradd -M -s /sbin/nologin nginx

# 更改工作目录
WORKDIR /usr/local/src/nginx-1.12.2

# 编译安装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

# 删除多余安装包 
RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz

# 设置环境变量
ENV PATH=/usr/local/nginx/sbin:$PATH

# 设置端口
EXPOSE 80
View Code

执行docker build 进行构建:

[root@server myNginx]# docker build -t centos_nginx:v1 .

构建成功后,查看新构建的镜像:

[root@server myNginx]# docker images

使用v1版本的镜像启动一个容器:

[root@server myNginx]# docker run -d -p 80:80 centos_nginx:v1 nginx -g "daemon off;"

查看容器运行状态:

[root@server myNginx]# docker ps 

这次构建完成了一个简单的实例。

 

标签:http,root,myNginx,module,server,nginx,构架,镜像,dockerfile
来源: https://www.cnblogs.com/topass123/p/12613097.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有