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:
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.
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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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:
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.
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!