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. Spring学习笔记(5)——IoC再度学习

    学习过Spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的,今天和大家 ...

  2. 求背景图片左边到#box盒子左边框外侧的距离

    box{ width: 100px; height: 200px; background: pink; padding: 100px; border: 80px solid; background-i ...

  3. texi2dvi - 打印 Texinfo 文档

    SYNOPSIS 总览 texi2dvi [OPTION]... FILE... DESCRIPTION 描述 依次从 Tex 系统中运行每个 Texinfo 或者 LaTex 文件 FILE,直到解 ...

  4. grep中正则表达式使用尖括号表示一个单词

    比如 grep '\<bin\>' /etc/passwd --color

  5. 关于SQL中 =:的含义

    一个很恶臭的例子来说明 =: 在sql语句中是做什么用的 int number= 114514: //众所周知野兽先辈的咆哮(世界级美声)是一串数字 var strSql = "select ...

  6. vue中的$nextTick的常用思路

    Vue 实现响应式并不是数据发生变化之后 DOM 立即变化,而是按一定的策略进行 DOM 的更新. $nextTick 是在下次 DOM 更新循环结束之后执行延迟回调,在修改数据之后使用 $nextT ...

  7. SQL 循环语句几种写法

    1.正常循环语句 declare @orderNum varchar(255)create table #ttableName(id int identity(1,1),Orders varchar( ...

  8. SQL复制数据表及表结构

    select * into 目标表名 from 源表名 insert into 目标表名(fld1, fld2) select fld1, 5 from 源表名 以上两句都是将'源表'的数据插入到'目 ...

  9. Dart编程实例 - Dart 面向对象编程

    Dart编程实例 - Dart 面向对象编程 class TestClass { void disp() { print("Hello World"); } } void main ...

  10. thinkphp整合后台模板

    将后台模板源码dist文件夹中的所有文件移动到thinkphp view index中 thinkphp的资源文件都不是从view文件夹下读取的 因此需要资源文件asset文件夹和demo文件夹放到t ...