问题描述
我有一个看起来像这样的docker-compose.yml文件
I have a docker-compose.yml file that looks something like this
version: "3.0"
volumes:
dbdata:
.:
services:
api:
build:
context: ./api
args:
- APP_NAME=${APP_NAME}
dockerfile: dockerfile
depends_on:
- database
- webserver
volumes:
- ./api:/usr/local/share/${APP_NAME}
database:
image: mysql:5.7
volumes:
- ./dbdata:/var/lib/mysql
restart: always
ports:
- ${COMPOSE_DB_PORT}:3306
webserver:
build:
context: .
dockerfile: webserver.dockerfile
working_dir: "/usr/local/share/${APP_NAME}"
volumes:
- ./api:/usr/local/share/${APP_NAME}
restart: always
ports:
- ${COMPOSE_APP_PORT}:80
它有3个服务.网站,数据库和Web服务器可以正常工作.
It has 3 services. a website, a database and a web server which works as expected.
现在我有另一个单独的Web项目,这是一个CMS,它使用与API项目相同的数据库,我想将其添加到此docker compose文件中,但是我不知道如何配置Web服务器服务来处理来自所述2个网站的请求.我应该为cms添加另一个Web服务器吗?
Now I have another separate web project which is a CMS that uses the same database as the API project and I want to add it to this docker compose file but I can't figure out how to configure the web server service to handle requests from said 2 web sites. Should I add another web server for the cms?
我在Google上进行了搜索,但找不到清晰的东西,大多数结果都使用了我不熟悉的旧docker-compose版本.
I searched on google but I couldn't find something clear and most results were using old docker-compose version which I'm not familiar with.
先谢谢了.
推荐答案
通常,您将有一个单独的Web服务器,该服务器公开并发布自己的端口(不在80上).
Normally, you would have a separate web server, which exposes and publishes its own port (not on 80).
您将拥有一个专用的侦听器(通常为NGiNX)以确保反向代理,以便根据查询的路径或端口将查询重定向到正确的Web服务器.
And you would have a dedicated listener (typically an NGiNX) to ensure a reverse proxy, in order to redirect the query to the right webserver, depending on its path or on the port.
由 K Hong .
例如参见" Docker compose:具有多个容器的NGINX反向代理"
这篇关于运行多个网站-Docker Compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!