0
0
Dockerdevops~20 mins

Docker Compose for dev environment - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Compose Dev Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of docker-compose up with multiple services
You run docker-compose up with this docker-compose.yml file:
version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  db:
    image: postgres:13
    environment:
      POSTGRES_PASSWORD: example

What will you see in the terminal output immediately after running the command?
Docker
version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  db:
    image: postgres:13
    environment:
      POSTGRES_PASSWORD: example
ABoth nginx and postgres containers start, logs from both services stream in the terminal.
BOnly nginx container starts; postgres container is created but not started.
CError: missing build context for nginx service.
DOnly postgres container starts; nginx container fails due to missing ports.
Attempts:
2 left
💡 Hint
Think about what docker-compose up does by default with multiple services.
Configuration
intermediate
2:00remaining
Correct volume syntax for live code reload
You want to mount your local ./app folder into the container at /usr/src/app to enable live code reload during development. Which volume syntax in docker-compose.yml is correct?
A
volumes:
  - ./app\:/usr/src/app
B
volumes:
  - /usr/src/app:./app
C
volumes:
  - /app:usr/src/app
D
volumes:
  - ./app:/usr/src/app
Attempts:
2 left
💡 Hint
Local path comes first, then container path separated by a colon.
Troubleshoot
advanced
2:00remaining
Why does docker-compose fail with 'port is already allocated' error?
You have this docker-compose.yml snippet:
services:
  web:
    image: nginx
    ports:
      - "8080:80"
  api:
    image: node
    ports:
      - "8080:3000"

You run docker-compose up and get an error: Bind for 0.0.0.0:8080 failed: port is already allocated. What is the cause?
Docker
services:
  web:
    image: nginx
    ports:
      - "8080:80"
  api:
    image: node
    ports:
      - "8080:3000"
AThe container port 80 is already used by another container.
BBoth services try to bind host port 8080, causing a conflict.
CDocker daemon is not running, so ports cannot be allocated.
DThe node image does not expose port 3000 by default.
Attempts:
2 left
💡 Hint
Host ports must be unique across all services.
🔀 Workflow
advanced
2:00remaining
Order of commands to update code in a running dev environment
You have a running dev environment with docker-compose up. You updated your local source code and want the container to use the new code without restarting the whole environment. What is the correct order of commands?
A1,3
B4,1,2
C3,1,2
D2,1,3
Attempts:
2 left
💡 Hint
You only need to rebuild and restart the containers to apply code changes.
Best Practice
expert
2:00remaining
Choosing the best way to share environment variables securely
You want to share sensitive environment variables like database passwords with your dev containers using Docker Compose. Which approach is best practice?
AHardcode passwords directly in the <code>docker-compose.yml</code> file under <code>environment</code>.
BPass environment variables at runtime using <code>docker-compose run -e</code>.
CStore secrets in a Docker Swarm secret and use <code>secrets</code> in Compose.
DUse a separate <code>.env</code> file and reference variables in <code>docker-compose.yml</code>.
Attempts:
2 left
💡 Hint
Think about secure storage and avoiding exposing secrets in files.