问题
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