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/


相关推荐
被瞧不起的神1 小时前
Docker 安装教程(CentOS 系统)纯新手可入门
docker·容器·centos
Thinbug3 小时前
群晖Nas - Docker(ContainerManager)上安装GitLab
docker·容器·gitlab
程序员阿超的博客5 小时前
云原生核心技术 (2/12): Docker 入门指南——什么是容器?为什么它比虚拟机更香?
docker·云原生·容器
Twilight-pending6 小时前
Docker重启流程解析
docker·容器·eureka
测试开发-学习笔记6 小时前
docker的常用命令
docker·容器
Smile_Gently7 小时前
基于服务器使用 apt 安装、配置 Nginx
nginx·ubuntu·debian
慈云数据7 小时前
从零搭建高性能企业级网站:Nginx + PHP-FPM 实战,全程用慈云数据服务器加持
服务器·nginx·php
GeminiJM8 小时前
Spring boot应用监控集成
运维·docker·容器
HGW6899 小时前
为什么已经有 Nginx 了,还需要服务网关?
nginx·spring cloud·微服务·架构