nginx dockerfile

Posted 牧之

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx dockerfile相关的知识,希望对你有一定的参考价值。

 

 nginx:1.22.1

 "muzhi"

 groupadd --system -g 2000 app \\
    && useradd app --system -m -s /bin/bash -u 2000 -g 2000 \\
    && usermod -a -G nginx app

 /home/app

# app/start.sh .
# app/docker-entrypoint-init.d docker-entrypoint-init.d
# app/docker-entrypoint.sh /usr/local/bin/

 etc/nginx/conf.d/default.conf /etc/nginx/conf.d/
 etc/nginx/nginx.conf /etc/nginx/

# chmod +x /usr/local/bin/docker-entrypoint.sh \\
#    && ln -s /usr/local/bin/docker-entrypoint.sh /entrypoint.sh

 mkdir -p /home/app/log && mkdir -p /var/run/nginx \\
    && chown -R app:app /home/app/log \\
    && chown -R nginx:nginx /var/log/nginx \\
    && chown -R nginx:nginx /var/cache/nginx \\
    && chown -R nginx:nginx /usr/lib/nginx \\
    && chown -R nginx:nginx /var/cache/nginx \\
    && chown -R nginx:nginx /var/run/nginx \\
    && chmod -R 775 /var/cache/nginx \\
    && chmod -R 775 /var/log/nginx \\
    && chown nginx:nginx /usr/sbin/nginx \\
    && chmod a+s /usr/sbin/nginx

 nginx

# ["docker-entrypoint.sh"]

 

 

 nginx:1.22.1

 "muzhi"

 cp /etc/apt/sources.list /etc/apt/sources.list.backup \\
    && sed -i "s@http://\\(deb\\|security\\).debian.org@https://mirrors.aliyun.com@g" /etc/apt/sources.list \\
    && apt-get update && apt-get install -y apt-utils

 apt-get install -y vim wget telnet net-tools tcpdump

 etc/nginx/conf.d/default.conf /etc/nginx/conf.d/
 etc/nginx/nginx.conf /etc/nginx/

 mkdir -p /var/run/nginx && chown -R nginx:nginx /var/run/nginx \\
    && chown -R nginx:nginx /var/cache/nginx \\
    && chown -R nginx:nginx /var/log/nginx \\
    && chown -R nginx:nginx /var/lib/nginx

 nginx

 

闲着无聊,今天就写个 dockerfile 定制 tomcat+nginx 集群

dockerfile 定制 tomcat+nginx 集群

前言(来张图)

一、dockerfile撰写 tomcat 镜像

FROM centos:7.4.1708
COPY jdk-8u201-linux-x64.rpm /opt
ADD apache-tomcat-9.0.16.tar.gz /opt
RUN cd /opt && rpm -qpl jdk-8u201-linux-x64.rpm \\
    && rpm -ivh jdk-8u201-linux-x64.rpm 
ENV JAVA_HOME /usr/java/jdk1.8.0_201-amd64
ENV CLASSPATH .:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
ENV PATH $JAVA_HOME/bin:$PATH 
RUN mv /opt/apache-tomcat-9.0.16 /usr/local/tomcat \\
    && mkdir /usr/local/tomcat/webapps/lucien \\
    && echo -e "<%@ page language=\\"java\\" import=\\"java.util.*\\" pageEncoding=\\"UTF-8\\"%> \\n<html>\\n<head>\\n<title>JSP test1 page</title>\\n</head>\\n<body>\\n<% out.println("1234567890");%>\\n</body>\\n</html>" > /usr/local/tomcat/webapps/lucien/index.jsp 
RUN sed -i '71a <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">' /usr/local/tomcat/conf/server.xml \\
    && sed -i '72a <Context docBase="/usr/local/tomcat/webapps/lucien" path="" reloadable="true">'  /usr/local/tomcat/conf/server.xml \\
    && sed -i '73a </Context>'  /usr/local/tomcat/conf/server.xml \\
    && sed -i '74a </Host>'  /usr/local/tomcat/conf/server.xml 
EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh","start"]

文件结构:

创建tomcat镜像:

二、dockerfile撰写 nginx 镜像

FROM centos:7.4.1708
ADD nginx-1.12.0.tar.gz /opt
RUN yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make \\
    && useradd -M -s /sbin/nologin nginx \\
    && cd /opt/nginx-1.12.0/ \\
    && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module \\
    && make \\
    && make install \\
    && ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \\
    && echo -e "events \\nuse epoll;\\nworker_connections  1024;\\n\\nhttp \\nupstream tomcat_server \\nserver 172.168.184.100:8080 weight=1;\\n\\nserver_tokens on;\\nserver \\nlisten       80;\\nserver_name  localhost;\\nlocation ~ .*\\.(gif|jpg|jpeg|png|bmp|swf|css)\\$ \\nroot /usr/local/nginx/html/xxx;\\nexpires 10d;\\n\\nlocation / \\nroot   html;\\nindex  index.html index.htmi index.php;\\n\\nerror_page   500 502 503 504  /50x.html;\\nlocation = /50x.html \\nroot   html;\\n\\nlocation ~ .*.jsp\\$ \\nproxy_pass http://tomcat_server;\\nproxy_set_header HOST \\$host;\\nproxy_set_header X-Real-IP \\$remote_addr;\\nproxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;\\n\\nlocation ~ \\.php$ \\nroot           html;\\nfastcgi_pass   172.168.184.30:9000;\\nfastcgi_index  index.php;\\nfastcgi_param  SCRIPT_FILENAME  \\$document_root\\$fastcgi_script_name;\\ninclude        fastcgi_params;\\n\\n\\n" > /usr/local/nginx/conf/nginx.conf
ENV PATH /usr/local/nginx/sbin:$PATH
WORKDIR /usr/local/nginx/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

文件结构:

创建 nginx 镜像:

三、查看镜像构建情况

四、分别开启nginx和tomcat

五、测试

以上是关于nginx dockerfile的主要内容,如果未能解决你的问题,请参考以下文章

dockerfile nginx配置

闲着无聊,今天就写个 dockerfile 定制 tomcat+nginx 集群

闲着无聊,今天就写个 dockerfile 定制 tomcat+nginx 集群

闲着无聊,今天就写个 dockerfile 定制 tomcat+nginx 集群

dockerfile构建nginx并结合php

dockerfile构建nginx并结合php