1、创建项目目录并上传包

$ mkdir docker_nginx
$ cd docker_nginx

下载nginx包

$ wget http://nginx.org/download/nginx-1.8.0.tar.gz

2、编辑Dockerfile

# From表示使用centos:latest这个镜像为基础构建我们的镜像
FROM centos:latest # 创建者的基本信息
MAINTAINER xiaozhou (xiaozhou@docker.com) LABEL Discription="基于centos的nginx镜像" version="1.0" # put nginx-1.8..tar.gz into /usr/local/src and unpack nginx
ADD nginx-1.8..tar.gz /usr/local/src #安装nginx所依赖的包
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel \
&& yum install -y libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel \
&& useradd -M -s /sbin/nologin nginx # change dir to /usr/local/src/nginx-1.8.
WORKDIR /usr/local/src/nginx-1.8. # execute command to compile 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 # nginx_config
RUN mkdir /usr/local/nginx/run \
&& sed -e '3i\user nginx;' -i /usr/local/nginx/conf/nginx.conf \
&& sed -e "9i\error_log /usr/local/nginx/logs/error.log;" -i /usr/local/nginx/conf/nginx.conf \
&& sed -e "12i\pid /usr/local/nginx/run/nginx.pid;" -i /usr/local/nginx/conf/nginx.conf \
&& sed -e "29i\ \taccess_log /usr/local/nginx/logs/access.log;" -i /usr/local/nginx/conf/nginx.conf # logrotate
RUN touch /etc/logrotate.d/nginx \
&& echo -e "$LOGS_DIR/*.log {" >> /etc/logrotate.d/nginx \
&& echo -e "\tdaily" >> /etc/logrotate.d/nginx \
&& echo -e "\trotate" >> /etc/logrotate.d/nginx \
&& echo -e "\tmissingok" >> /etc/logrotate.d/nginx \
&& echo -e "\tdateext" >> /etc/logrotate.d/nginx \
&& echo -e "\tcompress" >> /etc/logrotate.d/nginx \
&& echo -e "\tdelaycompress" >> /etc/logrotate.d/nginx \
&& echo -e "\tnotifempty" >> /etc/logrotate.d/nginx \
&& echo -e "\tsharedscripts" >> /etc/logrotate.d/nginx \
&& echo -e "\tpostrotate" >> /etc/logrotate.d/nginx \
&& echo -e "\t/usr/bin/kill -USR1 \`cat $LOGS_DIR/nginx.pid\`" >> /etc/logrotate.d/nginx \
&& echo -e "\tendscript" >> /etc/logrotate.d/nginx \
&& echo -e "\t}" >> /etc/logrotate.d/nginx ENV PATH /usr/local/nginx/sbin:$PATH EXPOSE EXPOSE CMD /bin/sh -c 'nginx -g "daemon off;"'

3、构建镜像

$ docker build -t centos:nginx .

4、启动容器

$ docker run -it -d -P 8 centos:nginx

查看启动的容器

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d350b2c8a3d5 centos:nginx "/bin/sh -c '/bin/sh…" 3 seconds ago Up 2 seconds 0.0.0.0:32769->80/tcp, 0.0.0.0:32768->443/tcp wonderful_elion

浏览器输入宿主机地址:
http://192.168.121.121:32769

可以看到 Welcome to nginx! 的页面,说明环境构建没问题。

docker Dcokerfile学习---构建nginx环境的更多相关文章

  1. docker Dockerfile学习---构建redis环境

    1.创建项目目录并下载包及文件 mkdir centos_redis cd centos_redis wget http://download.redis.io/releases/redis-5.0. ...

  2. docker Dockerfile学习---构建apache环境

    1.创建目录,上传包 创建项目目录 $ mkdir apache_php $ cd apache_php 把包下载后放到服务器该目录下 $ ls apr-....tar.gz 2.创建Dockerfi ...

  3. docker Dockerfile学习---构建mongodb环境

    1.创建项目目录并上传包 mkdir centos_mongodb cd centos_mongodb .tgz 2.编辑配置文件 vi mongodb.conf dbpath = /data/usr ...

  4. docker 灵活的构建 php 环境

    地址: https://github.com/ydtg1993/server           使用docker搭建灵活的线上php环境 有时候你可能不太需要一些别人已经集成了的包或者镜像      ...

  5. Docker容器学习梳理 - 基础环境安装

    以下是centos系统安装docker的操作记录 1)第一种方法:采用系统自带的docker安装,但是这一般都不是最新版的docker安装epel源[root@docker-server ~]# wg ...

  6. Nginx学习---企业级nginx环境搭建

    1.1. nginx安装环境 1.系统要求 nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境. 1-1 安装 GCC 源码安装nginx需要依赖gcc环境,需要 ...

  7. Docker学习之搭建nginx环境

    前言 很久没写随笔了,今天我们来学习一下如何在docker搭建nginx环境吧! 一:下载镜像,使用docker pull拉取最新的nginx镜像 命令:docker pull nginx 查看镜像: ...

  8. Docker学习之4——构建NGINX镜像

    Nginx是一个高性能的Web和反向代理服务器,它具有很多非常优越的特性:1.作为Web服务器.2.作为负载均衡服务器.3.作为邮件代理服务器.4.安装及配置简单.接下来我们介绍在docker构建ng ...

  9. docker学习8-搭建nginx环境

    前言 使用 docker 搭建 nginx 环境 下载镜像 使用docker pull 拉取最新的 nginx 镜像 [root@yoyo ~]# docker pull nginx Using de ...

随机推荐

  1. android中的SQLite数据库

    SQLite是android中集成的一个轻量级的数据库,该数据库支持绝大部分SQL92语法 SQLiteDatabase代表一个数据库(底层就是一个数据库文件),一旦应用程序获得了代表指定数据库的SQ ...

  2. 回头看看HTML5

    前言:自从学习各种框架各种成熟的控件库,越来越觉得疲惫. 一.用语义元素构造网页 在html5中最常用到的页面结构相关的语义元素如下: 页面结构想相关的语义元素 元素 说明 <article&g ...

  3. JNI中修改(基本类型)参数并返回到Java层使用

    最近在JNI相关项目中遇到一个问题:在Java层传入多个int类型的参数,在jni层修改参数值或地址之后重新返回到Java层.这应该算是基本知识了,尤其是基本类型的参数往往看似简单,所以在之前学习jn ...

  4. shell 编程四剑客简介 find sed grep awk(微信公众号摘抄)

    一,Shell编程四剑客之Find 通过如上基础语法的学习,读者对Shell编程有了更近一步的理解,Shell编程不再是简单命令的堆积,而是演变成了各种特殊的语句.各种语法.编程工具.各种命令的集合. ...

  5. 解决vcenter 6.0 vcsa安装插件第二个的时候报错的问题

    解决vcenter 6.0 vcsa安装插件第二个的时候报错的问题 需要打一下windows 的Microsoft v C++ 2013的2个补丁就可以正常运行了. 然后在后续安装过程中,到达最后一步 ...

  6. grep 正则2

    基本正则表达式所定义的元字符 元字符 作用 例子 例子说明 ^ 行首定位符 ^ty 匹配"t"开头,后面紧跟一个"y"的字符串 $ 行尾定位符 txt$ 匹配以 ...

  7. 【LeetCode】Hash

    [451] Sort Characters By Frequency [Medium] 给一个字符串,要求返回按照字母出现频率的排序后的字符串.(哈希表+桶排) 有个技巧是Hash用Value作为In ...

  8. Linux curl 命令模拟 POST/GET 请求

    Linux curl 命令模拟 POST/GET 请求   本文链接:https://blog.csdn.net/sunboy_2050/article/details/82156402 curl 命 ...

  9. asp.net MVC遇到的问题

    参考:http://blog.csdn.net/chenqiangdage/article/details/48996101 asp.netMVC 如何解决“上下文模型已在数据库创建后发生更改” 问题 ...

  10. DELPHI常用类型及定义单元

    Controls Application (the variable not a type) Forms Beep SysUtils or Windows (different functions) ...