docker Dcokerfile学习---构建nginx环境
2024-09-05 13:50:09
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! 的页面,说明环境构建没问题。
最新文章
- python实现grep
- bzoj1535[POI2005]sza-template
- 解决hibernate只能插入一条数据的问题
- 一个js(javascript)使用案例
- 解压vmlinuz和解压initrd(initramfs)
- C++单元测试2
- Linux文件权限与目录配置
- VHDL乘除法及转换
- 73、django之setting配置汇总
- Linux显示所有可更新的软件清单命令
- POJ1222熄灯问题
- 视频显著性检测-----Predicting Video Saliency using Object-to-Motion CNN and Two-layer Convolutional LSTM
- 【Linux基础】查看硬件信息-硬盘
- Oracle使用触发器和mysql中使用触发器的比较
- Java并发问题--乐观锁与悲观锁以及乐观锁的一种实现方式-CAS
- Linux学习笔记之四————Linux常用命令之文件管理
- hive数据类型
- @Html.DropDownListFor默认选中项
- Win10环境下Redis和Redis desktop manager 安装
- linux shell的执行方式
热门文章
- CF1215D
- 第二十五天 慵懒的投射在JDBC上的暖阳 —Hibernate的使用(四)
- Docker-搭建Docker Registry
- zabbix生产环境案例(三)
- mysql 使用 insert ignore into和unique实现不插入重复数据功能
- vue 学习六 在组件上使用v-model
- Packet for query is too large (1986748 >; 1048576). You can change this value on the server by 异常
- 59. jdk1.5新特性之----增强for循环
- Map集合类(二.其他map集合jdk1.8)
- 问题 |无法找到Python路径,需手动配置环境变量