The links option had 2 different meanings: one was defining a network, the other was defining an implicit dependence between the linking and the linked. This was instructing docker-compose to first start the creation of the linked service, and then the the creation of the linking one. Without links:, the latter is lost, so depends_on does the missed effect, telling docker-compose of the dependency, but using a more explicit declaration.
Now we wanna start using some of the new features of V2 and, as first, we can remove the links option. When docker-compose execute V2 files, it will automatically build a network between all of the containers defined in the file, and every container will be immediately able to refer to the others just using the names defined in the docker-compose.yml file.
So we don’t need links anymore; links was used to start a network communication between our db container and our web-server container, but this is already done by docker-compose. Here is the new version of our file:
The links option at the end of the file will instruct docker-compose to open a network between the express-app-container and the dbpostgres linked containers. Docker-compose will also change the etc/hosts file on the express-app-container container, adding an host name (dbpostgres), so the express.js application can reach the postgres database in the linked container with something like this: