Docker Compose
Lab Solution
The sample solution lab/compose.yaml adds:
- a network called
front-endwith no options, so it will be created with the Docker defaults - a service called
nginxwhich uses the Nginx image and connects to thefront-endandapp-netnetworks.
Compose uses the directory name of the YAML file to identify the application - so to update the app, the Compose file needs to be copied to the rng folder.
Copy the Compose file and deploy the update:
cp ./labs/compose/lab/compose.yml ./labs/compose/rng/lab.yml
docker compose -f ./labs/compose/rng/lab.yml up -dYou'll see the new network and container created, but the RNG web and API containers will be left unchanged. The spec hasn't changed for those services, so the containers match the desired state.
Inspect the new container to show the network details:
docker inspect rng-nginx-1You'll see it has two IP addresses in the network section at the end of the output. This is one IP from each network - like a machine with two network cards.
Test connectivity from the Nginx container to the web container:
docker exec rng-nginx-1 nslookup rng-webThe new container can resolve IP addresses for the original container.
And from the web container to Nginx:
docker exec rng-rng-web-1 ping -c3 nginxThe old containers can reach the new one.
Back to the exercises.