原创

docker部署tomcat,nginx,java应用

1.Dockerfile

Dockerfile文件

FROM centos:latest

RUN yum install -y unzip
RUN yum -y install make automake zlib zlib-devel gcc-c++ libtool  openssl openssl-devel pcre pcre-devel 
RUN mkdir -p /export/servers/source

COPY apache-tomcat-8.5.32.zip /export/servers/
RUN cd /export/servers/;unzip -q apache-tomcat-8.5.32.zip

COPY jdk1.8.0_211.zip /export/servers/
RUN cd /export/servers/;unzip -q jdk1.8.0_211.zip

COPY nginx-1.16.1.zip /export/servers/source
RUN cd /export/servers/source;unzip -q nginx-1.16.1.zip
RUN cd /export/servers/source/nginx-1.16.1; ./configure \
--prefix=/export/servers/nginx \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-file-aio \
--with-http_realip_module  && make && make install


ENV JAVA_HOME /export/servers/jdk1.8.0_211
ENV PATH $PATH:$JAVA_HOME/bin
RUN java -version

COPY docker-entrypoint.sh /export/servers/source/
ENTRYPOINT ["/usr/sbin/init"]

自备apache-tomcat-8.5.32.zip,nginx-1.16.1.zip,jdk1.8.0211.zip

1.编译安装nginx
2.安装jdk8以及环境变量设置
3.手动进入容器启动nginx和tomcat即可

2.docker-compose.yml文件

version: '3'
services:
    jtn:
        build: .
        privileged: "true"
        ports:
            - "8580:8080"
            - "8581:80"
        restart: always

依赖Dockerfile文件

3.docker-entrypoint.sh文件参考

/usr/sbin/init && \ 
cd /export/servers/nginx/sbin && \ 
./nginx && \ 
sh /export/servers/apache-tomcat-8.5.32/bin/startup.sh && \

可以自己改改

4.运行

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                          NAMES
3f4152d46a77        tomcat8_jtn         "/usr/sbin/init"    8 minutes ago       Up 8 minutes        0.0.0.0:8581->80/tcp, 0.0.0.0:8580->8080/tcp   tomcat8_jtn_1
正文到此结束
本文目录