Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

docker-compose怎么配置nginx多域名、https

web容器Dockerfile:

FROM node:latest

MAINTAINER YW

RUN mkdir -p /home/projects/web

WORKDIR /home/projects/web

COPY . /home/projects/web

RUN npm install

RUN npm run build

EXPOSE 9999

CMD [ "npm", "start"]

docker-compose文件怎么用nginx映射到web容器暴露的9999端口中,https又怎么用呢,多域名又如何配置呢?

version: '3.1'
services:
    web:
        build: .       
        container_name: web 
        restart: always         
        network_mode: host

跪求大佬指点


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

如果nginx也是容器,不需要端口映射,直接把整个服务映射进去

services:
  web: 
    ...
    
  nginx:
    ...
    depends_on:
      - web

如果nginx在宿主机上:

services:
  web: 
    ...
    ports:
      - 9999:9999
    

通过ports属性,把容器的端口映射到宿主机的端口


至于https和多域名,完全就是nginx内部配置了,与docker-compose无关


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...