DEV Community

Discussion on: Learn Docker — from the beginning, part V Docker Compose, variables, volumes, networks and databases

Collapse
 
clhenrick profile image
Chris Henrick

Thanks for this excellent and well written walk through of Docker, it's helped me out quite a bit with a personal project I'm working on.

A couple important things that I didn't quite catch from this post relating to how the database container communicates to the service container that I think are worth calling out:

  1. When you reference your database from your app service, the database host name is the same as the database service in the docker-compose.yml In your example this is "db". This seems obvious now but wasn't apparent to me at first.

  2. For other database systems such as PostgreSQL where you need to specify the port number in the connection, the port to use is the container port, not the host port that it's mapped to. Using your example this would be 3306 not 8002.

For my use case I'm using PostgreSQL and the node-postgres library, so it's slightly different than MySQL, but I imagine others may run into this as well!