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/


相关推荐
.Hypocritical.29 分钟前
Tomcat本地部署+远程服务器部署超详细教程
java·服务器·tomcat
2601_962128263 小时前
Nginx知识详解(理论+实战更易懂)
运维·nginx
Larru-Sun3 小时前
从零开始用 Docker 部署 Node.js 后端服务
docker·容器·node.js
feilieren4 小时前
ubuntu 安装 docker
linux·ubuntu·docker
judezh5 小时前
一个 Agent 平台要起 12 个容器,做演示能砍到几个?
docker
飞询5 小时前
ubuntu 安装 docker
ubuntu·docker
2601_962122975 小时前
解决 IntelliJ IDEA 中 Tomcat 日志乱码问题的详细指南
java·tomcat·intellij-idea
2601_962203515 小时前
Nginx 安装配置
运维·nginx
mister_guo6 小时前
Docker、Docker Compose 与 Kubernetes:分别解决什么问题?
docker·容器·kubernetes
浮生望15 小时前
Docker 入门实战:容器化思想、nginx 反向代理与容器生命周期管理
docker