0
0
Dockerdevops~10 mins

Container DNS and service discovery in Docker - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run a container with a custom network for DNS-based service discovery.

Docker
docker network create my_network

docker run --rm -d --name webapp --network [1] nginx
Drag options to blanks, or click blank then click option'
Abridge
Bnone
Chost
Dmy_network
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bridge' network which does not enable container name DNS resolution.
Using 'host' network which bypasses Docker networking.
Forgetting to create the custom network before running the container.
2fill in blank
medium

Complete the command to run a second container that can reach the first container by its name using Docker DNS.

Docker
docker run --rm -it --network my_network busybox ping [1]
Drag options to blanks, or click blank then click option'
Alocalhost
B127.0.0.1
Cwebapp
Dgoogle.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'localhost' which refers to the current container.
Using an external domain like 'google.com' which is unrelated to Docker DNS.
3fill in blank
hard

Fix the error in the Docker Compose service definition to enable service discovery by service name.

Docker
version: '3'
services:
  app:
    image: myapp
    networks:
      - [1]
networks:
  mynet:
    driver: bridge
Drag options to blanks, or click blank then click option'
Amynet
Bbridge
Cdefault
Dhost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bridge' which is a driver, not the network name.
Using 'host' which disables Docker network isolation.
4fill in blank
hard

Fill both blanks to create a Docker Compose file that defines two services communicating via service names on a custom network.

Docker
version: '3'
services:
  frontend:
    image: frontend_image
    networks:
      - [1]
  backend:
    image: backend_image
    networks:
      - [2]
networks:
  appnet:
    driver: bridge
Drag options to blanks, or click blank then click option'
Aappnet
Bbridge
Cdefault
Dhost
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning different networks to services prevents DNS-based communication.
Using 'default' network name which is not defined explicitly.
5fill in blank
hard

Fill all three blanks to create a Docker Compose snippet that uses environment variables to configure the backend service URL for the frontend service.

Docker
version: '3'
services:
  frontend:
    image: frontend_image
    environment:
      - BACKEND_URL=http://[1]:[2]
    networks:
      - [3]
  backend:
    image: backend_image
    networks:
      - appnet
networks:
  appnet:
    driver: bridge
Drag options to blanks, or click blank then click option'
Abackend
B8080
Cappnet
Dfrontend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'frontend' as hostname instead of 'backend'.
Using wrong port number or network name.