Running multiple websites - docker compose

你离开我真会死。 提交于 2020-01-03 01:59:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!