I recently added a new service stack in my dev process with docker. This service stack is composed of many services I can use in different projects managed with docker-compose.
Docker-compose service layer
There are two ways I know to use this mailcatcher service inside many projetcs :
- A mailcatcher container for each projet (
- A single mailcatcher container for all projects (catching all projects mails):
and inside your
docker-compose.yml files :
Internally docker will automatically add new entry in the
of each container using the mailcatcher service with the targeted container IP address:
It allows you us to use this local domain name instead of the mailcatcher container IP address. Useful because this IP will change each time the service container is restarted.
Using links and external links can lead to problems. Indeed, sometimes (do not really know why or when) the container that as dependencies on other services, cannot reach the local host domains at startup.
I can see two reasons for this:
- The service container is starting and the startup process of the main/app container is not finished yet.
- The application you run (apache, nginx,…) starts before the
/etc/hostsfile has been updated internally by docker.
So far, the only solution I have to fix the problem is to wait for local domains to become reachable, thanks to a shell script (you need netcat/nc command installed):
Use this script in the CMD section of the
Dockerfile or in a custom startup script.
You must set an environment variable to define hosts to wait for (with a specific format HOST:PORT):
- As you can see you can wait for an outside host to become available.
- You can wait for links AND external_links.