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. netease-cloud-music : 依赖: libqt5x11extras5 (>= 5.1.0) 但是它将不会被安装

    修复一下依赖关系: sudo apt-get install -f #或者:sudo apt-get -f install 上面两条是修复依赖关系(depends)的命令,就是假如你的系统上有某个pa ...

  2. MNIST多图显示--Python练习

    在学习TensorFlow框架时,提到用MNIST手写数字数据库进行练习,为了更直观看下里面的数据到底长啥样,用OpenCV(cv2)中的imshow函数来进行显示. 默认已经安装: numpy.te ...

  3. $@、$*和环境变量IFS

  4. Codeforces 1140F 线段树 分治 并查集

    题意及思路:https://blog.csdn.net/u013534123/article/details/89010251 之前cf有一个和这个相似的题,不过那个题只有合并操作,没有删除操作,直接 ...

  5. Java中的Set集合以及HashSet

    Set集合: Set继承自Collection,所以没有什么特别的方法. 需要注意的是,Set集合不包含重复元素,我们重点了解Set集合如何保证不包含多余元素. HashSet: HashSet如何保 ...

  6. spring在注解标注的方法上加切面

    之前以为只能在方法签名上加切面,今天发现注解上也能加切面 1.自定义一个注解(任意注解都可以,不一定是自定义的) @Target({ElementType.METHOD}) @Retention(Re ...

  7. git——创建分支后,切换分支报错(error: pathspec 'master' did not match any file(s) known to git)

    error: pathspec 'master' did not match any file(s) known to git 解决办法: 1.查看分支 git branch -a 2.获取所有分支 ...

  8. JVM调优学习 【更新中】

    JVM调优(jdk1.8) 老生常谈,面试吹牛的的最佳谈资,在接下来的几天里,我找了点资料来对其进行一波学习: 本地环境是不需要对我们的虚拟机进行优化的,一般在生产环境下,也就是Linux下才有对JV ...

  9. 【Codeforces Round #429 (Div. 2) C】Leha and Function

    [Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...

  10. 栈+括号序列+暴力枚举——cf1248D1

    这个复杂度首先就想到是n3的复杂度,n2枚举换的位置,求值在花费n复杂度 判断一个序列有多少独立的括号子串时用栈处理一下即可 /* 枚举交换两个括号的位置,然后再对新的序列判一次即可 */ #incl ...