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! 的页面,说明环境构建没问题。

最新文章

  1. python实现grep
  2. bzoj1535[POI2005]sza-template
  3. 解决hibernate只能插入一条数据的问题
  4. 一个js(javascript)使用案例
  5. 解压vmlinuz和解压initrd(initramfs)
  6. C++单元测试2
  7. Linux文件权限与目录配置
  8. VHDL乘除法及转换
  9. 73、django之setting配置汇总
  10. Linux显示所有可更新的软件清单命令
  11. POJ1222熄灯问题
  12. 视频显著性检测-----Predicting Video Saliency using Object-to-Motion CNN and Two-layer Convolutional LSTM
  13. 【Linux基础】查看硬件信息-硬盘
  14. Oracle使用触发器和mysql中使用触发器的比较
  15. Java并发问题--乐观锁与悲观锁以及乐观锁的一种实现方式-CAS
  16. Linux学习笔记之四————Linux常用命令之文件管理
  17. hive数据类型
  18. @Html.DropDownListFor默认选中项
  19. Win10环境下Redis和Redis desktop manager 安装
  20. linux shell的执行方式

热门文章

  1. CF1215D
  2. 第二十五天 慵懒的投射在JDBC上的暖阳 —Hibernate的使用(四)
  3. Docker-搭建Docker Registry
  4. zabbix生产环境案例(三)
  5. mysql 使用 insert ignore into和unique实现不插入重复数据功能
  6. vue 学习六 在组件上使用v-model
  7. Packet for query is too large (1986748 > 1048576). You can change this value on the server by 异常
  8. 59. jdk1.5新特性之----增强for循环
  9. Map集合类(二.其他map集合jdk1.8)
  10. 问题 |无法找到Python路径,需手动配置环境变量