问题
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
It has 3 services. a website, a database and a web server which works as expected.
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?
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.
Thanks in advance.
回答1:
Normally, you would have a separate web server, which exposes and publishes its own port (not on 80).
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.
by K Hong.
See for instance "Docker compose : NGINX reverse proxy with multiple containers "
来源:https://stackoverflow.com/questions/47849096/running-multiple-websites-docker-compose