Complete the command to create a Docker network named 'mynetwork'.
docker network create [1]The command docker network create mynetwork creates a new user-defined network named 'mynetwork'. This network allows containers to communicate by name.
Complete the command to run a container named 'web' attached to the 'mynetwork' network.
docker run -d --name web --network [1] nginxUsing --network mynetwork attaches the container to the user-defined network 'mynetwork', enabling DNS resolution between containers on that network.
Fix the error in the command to ping the 'web' container from another container on the same network.
docker run --rm --network mynetwork alpine ping -c 3 [1]
Using the container name 'web' allows DNS resolution within the 'mynetwork' network, so the ping command reaches the correct container.
Fill both blanks to create a Docker Compose service named 'db' using the 'mysql' image and connect it to the 'mynetwork' network.
services:
db:
image: mysql
networks:
- [1]
networks:
[2]:Both blanks should be 'mynetwork' to define and use the same custom network in Docker Compose, enabling DNS resolution between services.
Fill all three blanks to define a Docker Compose service 'app' that depends on 'db', uses the 'mynetwork' network, and sets an environment variable 'DB_HOST' to the 'db' service name.
services:
app:
image: myapp
depends_on:
- [1]
environment:
- DB_HOST=[2]
networks:
- [3]The 'app' service depends on 'db', sets the environment variable 'DB_HOST' to 'db' so it can connect by name, and uses the 'mynetwork' network for DNS resolution.