Container 2 Container Networking
-
One rule: If two containers are on the same network then they can talk to each other. If they aren’t, they can’t.
-
Docker allows us to create networks to allow separate containers to talk to each other via service discovery. No need to use IP addresses, a container name is all you need!
-
The Docker CLI does allow us to create networks and set up containers within them but its somewhat manual and there is a much better tool included with Docker to do the job.
Docker Compose
Don't worry its installed by default
The recommended approach to setting up multiple containers.
Let's take a look at the docker-compose.yml
file under the app
directory
docker-compose up --build -d
- --builds the image for us
- We don't always want to build the image, if we haven't made any code changes then we can skip building
- -d detached mode again so we can still use the terminal
To stop your containers
docker-compose down
Logs
docker-compose logs