Repository navigation
Home
NOTE: Check out dream for a fancy, low maintenance option
For simple development environments, a neat way to handle this is to put your connected containers on the same network, and give them simple fixed container names.
First create your network (for example, we'll use the name myapps): docker-machine network create myapps
Then in each project's docker-compose.yml you must make the following changes:
- Set the
versionto 2, which includes nesting your services under theserviceskey - Add a unique
container_nameto your app service - Add the
defaultandmyappsnetworks to the app servicenetworkskey - Add the
networksconfig to mark the network as external
Example using a simple railsy compose file:
version: '2'
services:
db:
image: postgres
app:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000"
links:
- db
networks:
- default
- myapps
container_name: app_one
networks:
myapps:
external: true
Finally docker-compose up - your containers can now reference each other by their container_name.
Note: The container_name step is essential if your containers would be by default be named with underscores, as Ruby's URI lib doesn't like them
This can also all be made more fanciful with a DNS container - but that's a bit beyond a simple setup.
During testing I encountered this often, yet does not seem to be a problem with docker itself. It seems to be due to server.pid not being cleaned up, so a simple fix is to remove this file as part of the app service command:
app:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/app
ports:
- "3000"
links:
- db