0
0
Dockerdevops~20 mins

Defining services in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Service Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of docker-compose service start command
What is the output when you run docker-compose up -d with this docker-compose.yml file?
Docker
version: '3.8'
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
ACreating network "default" with the default driver\nCreating default_web_1 ... done
BError: Service 'web' has no container_name specified
CCreating network "default" with the default driver\nCreating volume "default_web_data" with default driver\nCreating default_web_1 ... done
DStarting web ... done
Attempts:
2 left
💡 Hint
Focus on what docker-compose creates by default when starting a service without volumes.
Configuration
intermediate
2:00remaining
Correct service definition for environment variables
Which service definition correctly sets environment variables for a service in docker-compose.yml?
A
services:
  app:
    image: myapp
    environment:
      - DEBUG=true
      - PORT=3000
B
services:
  app:
    image: myapp
    env:
      DEBUG: true
      PORT: 3000
C
services:
  app:
    image: myapp
    environment:
      DEBUG: true
      PORT: 3000
D
services:
  app:
    image: myapp
    env_vars:
      - DEBUG=true
      - PORT=3000
Attempts:
2 left
💡 Hint
Check the correct key name and format for environment variables in docker-compose.
Troubleshoot
advanced
2:00remaining
Troubleshooting service port binding error
You defined this service in docker-compose.yml but get an error when starting it: Bind for 0.0.0.0:80 failed: port is already allocated. What is the cause?
Docker
services:
  web:
    image: nginx
    ports:
      - "80:80"
AAnother process on the host is already using port 80, so Docker cannot bind it.
BThe image 'nginx' does not expose port 80, causing the error.
CThe ports syntax is incorrect; it should be '80->80' instead of '80:80'.
DDocker daemon is not running, so ports cannot be bound.
Attempts:
2 left
💡 Hint
Check if any other application is using the host port before Docker tries to bind it.
🔀 Workflow
advanced
2:00remaining
Order of steps to update a running service with new image
What is the correct order of commands to update a running service to use a new image version in Docker Compose?
A3,2,1,4
B1,3,2,4
C1,2,4,3
D3,1,2,4
Attempts:
2 left
💡 Hint
You want to stop the old containers before pulling and starting new ones.
Best Practice
expert
2:00remaining
Best practice for defining multiple services sharing a network
Which docker-compose service definition best ensures two services share the same user-defined network named 'appnet'?
A
networks:
  appnet:
services:
  service1:
    image: alpine
    networks:
      - appnet
  service2:
    image: alpine
    networks:
      - appnet
B
services:
  service1:
    image: alpine
    networks:
      - appnet
  service2:
    image: alpine
    networks:
      - appnet
networks:
  appnet:
    driver: bridge
C
services:
  service1:
    image: alpine
  service2:
    image: alpine
networks:
  appnet:
    driver: bridge
D
services:
  service1:
    image: alpine
  service2:
    image: alpine
    networks:
      - appnet
Attempts:
2 left
💡 Hint
Define the network under 'networks' and attach it explicitly to each service.