Can you use nginx reverse proxy to docker containers without exposing any ports?

余生颓废 提交于 2020-01-23 03:25:27

问题


I'd like to know if it's possible to use nginx with docker compose as an api gateway / reverse proxy / ssl termination point without exposing any ports on the containers behind it. I.e. I want to use only the intranet created by docker compose when the containers are linked to communicate past nginx. Ideally the only publicly accessible port will be port 443 (ssl) on nginx. Is this doable? Or do I have to expose ports on my containers?


回答1:


Yes is doable.

Just define your application in one container and nginx in another container, both in the same docker-compose.yml. Link them. And only expose the 443 port in nginx container.

docker-compose.yml

nginx:
    image: nginx
    links:
        - node1:node1
        - node2:node2
        - node3:node3
    ports:
        - "443:443"
node1:
    build: ./node
node2:
    build: ./node
node3:
    build: ./node

More info: http://anandmanisankar.com/posts/docker-container-nginx-node-redis-example/

Regards



来源:https://stackoverflow.com/questions/40144250/can-you-use-nginx-reverse-proxy-to-docker-containers-without-exposing-any-ports

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