Skip to content

Instantly share code, notes, and snippets.

@cblunt
Last active August 7, 2018 12:54
Show Gist options
  • Save cblunt/63bea4dd18676cb4e5654e5950defa31 to your computer and use it in GitHub Desktop.
Save cblunt/63bea4dd18676cb4e5654e5950defa31 to your computer and use it in GitHub Desktop.
Linking Containers across Multiple Docker Compose Projects
version: '3.2'
networks:
default:
external:
name: my_net # Needs to be manually created using docker network create
services:
nginx:
image: jwilder/nginx-proxy
ports:
- '80:80'
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
db:
image: postgres
web_one:
build: .
depends_on:
- db
- nginx
volumes:
- .:/app
environment:
- RAILS_ENV=development
- VIRTUAL_HOST=app_one.local
version: '3.2'
networks:
default:
external:
name: my_net # Needs to be manually created using docker network create
services:
web_two:
build: .
volumes:
- .:/app
depends_on:
- db
- nginx
environment:
- RAILS_ENV=development
- VIRTUAL_HOST=app_two.local
# Optionally use a different database on the same postgres container.
# - POSTGRES_DB=app_two_development
$ docker network create my_net
$ docker-compose -f docker-compose.1.yml run --rm web_one bin/rails db:setup
$ docker-compose -f docker-compose.1.yml -f docker-compose.2.yml up -d
$ open http://app_one.local http://app_two.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment