I am setting up my local development environment with docker containers. The docker-compose.yml is like following
version: \'2\'
services:
db:
image:
When you use service definition version 2 and more, docker-compose
creates user-defined network. Name resolution in a user-defined network works via Docker embedded DNS server. Here's related quote from documentation:
The Docker embedded DNS server enables name resolution for containers connected to a given [user-defined] network. This means that any connected container can ping another container on the same network by its container name.
Containers are also available by network aliases that docker-compose
creates. It can be verified by command like:
docker inspect \
-f '{{json .NetworkSettings.Networks.myapp_default.Aliases}}' my_app_db_1
It prints ["db","$CONTAINER_ID"]
.
Providing links with --link
will not have any effect in case of existing user-defined network. You can make sure and look at /etc/hosts
, which will not have the corresponding lines.
Thus the following command is sufficient:
docker run -it --net myapp_default worker