Created
November 10, 2017 18:13
-
-
Save BretFisher/f1d1be2a8ab6df379018bcbf766e74a4 to your computer and use it in GitHub Desktop.
Docker Compose local development with wildcard DNS for multi-domain development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
# vcap.me is a wildcard domain that resolves to localhost | |
# in case you need to pass URL's around from browser to | |
# containers this could help you get around localhost problem | |
services: | |
# use www.vcap.me to access web containter from host | |
# use api.vcap.me to access api container from host | |
proxy: | |
image: nginx | |
volumes: | |
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro | |
ports: | |
- '80:80' | |
# web can talk to api directly via api.vcap.me | |
web: | |
image: httpd | |
volumes: | |
- ./web:/usr/local/apache2/htdocs/ | |
# maybe your web container needs to access api container | |
# but use a URL fed to it by browser on host | |
# this will re-map the DNS to prevent localhost | |
# note this doesn't work in Swarm, only for local dev | |
external_links: | |
- api:api.vcap.me | |
api: | |
image: httpd | |
volumes: | |
- ./api:/usr/local/apache2/htdocs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
server_name www.vcap.me; | |
location ~ { | |
proxy_pass http://web; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $server_name; | |
} | |
} | |
server { | |
server_name api.vcap.me; | |
location ~ { | |
proxy_pass http://api; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $server_name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment