Docker Compose 部署Nginx反向代理 tomcat

Nginx 、Tomcat (默认端口8080)》》compose

csharp 复制代码
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    restart: always
    ports:
      - 80:80
      - 8080:8080
    volumes:
      # 文件夹会自动创建,但nginx.conf是文件,需要提前创建,否则 会自动创建nginx.conf文件夹
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./html:/usr/share/nginx/html
  tomcat1:
    image: tomcat:latest
    container_name: tomcat1

  tomcate2:
    image: tomcat:latest
    container_name: tomcat2

nginx的配置文件

csharp 复制代码
worker_processes  2;

events {
    worker_connections  1024;
}

http {
   upstream httpd {
        server tomcat1:8080 weight=10;
        server tomcat2:8080 weight=10;
   }
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   server {
       listen       80;
       #  为了模拟域名访问,  需要在访问的客户端 host 加   IP  service.zen.com
       server_name  service.zen.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
          proxy_pass http://httpd;
        }

    }

}

运行 compose

csharp 复制代码
#  运行 compose
docker compose up -d

# 查看运行的容器进程
docker ps

# 因tomcat 拉取 阿里云的, 阿里云是处理过的 ,保留核心的内容了
# 进入tomcat 容器
docker exec -it tomcat容器ID   /bin/bash
# 阿里云拉取的 tomcat   /usr/local/tomcat/webapps  是空的 阿里云把内容 存在 webapps.dist文件夹里了
cp -r  webapps.dist/* webapps/


相关推荐
火山上的企鹅34 分钟前
Codex实战:APP远程升级服务搭建(二)阿里云ECS部署Node升级服务_Ubuntu_systemd_Nginx
nginx·ubuntu·阿里云·qgc
難釋懷1 小时前
Nginx-UpStream工作流程
运维·nginx
极客先躯1 小时前
高级java每日一道面试题-2026年02月03日-实战篇[Docker]-如何备份和恢复 Docker Volume?
运维·docker·容器·自动化·备份·持久化·恢复
“码”力全开1 小时前
基于 Docker 与边缘计算的 AI 视频管理平台:打破 GB28181/RTSP 协议壁垒与源码交付架构解析
人工智能·docker·边缘计算
難釋懷1 小时前
Nginx-AB安装
运维·nginx
江湖有缘1 小时前
自建私有任务管理平台|Docker Compose部署Ticky完整教程
运维·docker·容器
ai产品老杨1 小时前
破局多路异构计算:基于 Docker 容器化与 GB28181/RTSP 统一接入的 AI 边缘计算视频管理平台架构解析
人工智能·docker·边缘计算
梦想的颜色1 小时前
Docker 知识全貌:一份体系化的知识结构报告
docker·云原生·容器·eureka
“码”力全开4 小时前
架构师视角的自研流媒体中台:基于 Docker、GB28181 与 RTSP 的边缘计算 AI 平台,源码交付赋能二次开发
人工智能·docker·边缘计算
杨浦老苏10 小时前
家庭实验室监控仪表盘HomeLab-Monitor
运维·docker·监控·群晖