0
0
Dockerdevops~20 mins

Container DNS and service discovery in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Container DNS Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Docker container DNS resolution output
You have two Docker containers running on the same user-defined bridge network named mynetwork. Container A tries to ping Container B using its container name. What will be the output of the ping command inside Container A?
Docker
docker network create mynetwork

docker run -dit --name containerB --network mynetwork alpine sh

docker run -dit --name containerA --network mynetwork alpine sh

docker exec containerA ping -c 1 containerB
A
PING containerB (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.123 ms

--- containerB ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
Bping: bad address 'containerB'
Cconnect: Network is unreachable
Dping: unknown host containerB
Attempts:
2 left
💡 Hint
Containers on the same user-defined bridge network can resolve each other by container name.
🧠 Conceptual
intermediate
1:30remaining
Service discovery mechanism in Docker Swarm
Which of the following best describes how service discovery works in Docker Swarm mode?
ADocker Swarm requires manual editing of /etc/hosts files on each node for service discovery.
BDocker Swarm uses external DNS servers only and does not provide built-in service discovery.
CDocker Swarm uses an internal DNS server that resolves service names to the IP addresses of active service tasks.
DDocker Swarm uses multicast network broadcasts to discover services automatically.
Attempts:
2 left
💡 Hint
Think about how Docker Swarm manages multiple replicas of a service.
Troubleshoot
advanced
2:00remaining
Troubleshooting container DNS failure on default bridge network
You run two containers on the default Docker bridge network. Container A tries to ping Container B by its container name but fails with ping: unknown host containerB. What is the most likely cause?
AContainers on the default bridge network cannot resolve each other by container name because it lacks embedded DNS support.
BThe containers are on different Docker hosts, so DNS resolution fails.
CThe container names are case-sensitive and must be uppercase.
DThe Docker daemon is not running, causing DNS failures.
Attempts:
2 left
💡 Hint
Consider the difference between default and user-defined bridge networks.
🔀 Workflow
advanced
1:30remaining
Configuring service discovery with Docker Compose
Given the following Docker Compose snippet, what hostname should web service use to connect to the db service?
Docker
version: '3.8'
services:
  web:
    image: nginx
    depends_on:
      - db
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: example
Aweb
Blocalhost
Cmysql
Ddb
Attempts:
2 left
💡 Hint
Services in the same Docker Compose network can reach each other by service name.
Best Practice
expert
2:30remaining
Best practice for service discovery in multi-host Docker environments
In a multi-host Docker environment without Swarm, which approach is best to enable reliable service discovery across hosts?
AUse container names as hostnames and expect Docker to resolve them across hosts automatically.
BUse an external service discovery tool like Consul or etcd integrated with Docker containers.
CRely on Docker's default bridge network DNS for cross-host discovery.
DManually update /etc/hosts on all hosts with container IPs.
Attempts:
2 left
💡 Hint
Think about scalability and automation in multi-host setups.