0
0
Dockerdevops~20 mins

Database containers for local development in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Database Container Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Docker command for running a PostgreSQL container
You run this command to start a PostgreSQL container locally:
docker run --name pg-test -e POSTGRES_PASSWORD=secret -d -p 5432:5432 postgres:15

What is the output of docker ps --filter name=pg-test --format '{{.Status}}' immediately after running?
AUp 5 seconds
BRestarting (1) 3 seconds ago
CCreated
DExited (1) 2 seconds ago
Attempts:
2 left
💡 Hint
Think about what status a healthy running container shows.
Configuration
intermediate
2:00remaining
Correct Docker Compose service for MySQL with persistent data
Which Docker Compose service configuration correctly sets up a MySQL container with a persistent volume for data storage?
A
services:
  db:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
    volumes:
      - /var/lib/mysql
volumes:
  mysql-data:
B
services:
  db:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
    volumes:
      - mysql-data:/var/lib/mysql
volumes:
  mysql-data:
C
services:
  db:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
    volumes:
      - ./data:/var/lib/mysql
volumes:
  mysql-data:
D
services:
  db:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
    volumes:
      - mysql-data:/etc/mysql
Attempts:
2 left
💡 Hint
Persistent data should be stored in the container's data directory, not config directory.
Troubleshoot
advanced
2:00remaining
Diagnosing PostgreSQL container connection failure
You start a PostgreSQL container with:
docker run --name pg -e POSTGRES_PASSWORD=pass -d -p 5432:5432 postgres

But when you try to connect from your host using psql -h localhost -p 5432 -U postgres, it fails with "connection refused".
What is the most likely cause?
ADocker daemon is not running
BThe port 5432 is blocked by the container firewall
CThe POSTGRES_PASSWORD environment variable was not set correctly
DPostgreSQL inside the container is not listening on all interfaces, only on localhost inside container
Attempts:
2 left
💡 Hint
Think about how PostgreSQL listens for connections inside the container versus outside.
🔀 Workflow
advanced
2:00remaining
Order of steps to safely update a database container with data persistence
You want to update your MySQL container image to a newer version without losing data stored in a Docker volume.
Which is the correct order of steps?
A1,2,3,4
B2,1,3,4
C1,3,2,4
D3,1,2,4
Attempts:
2 left
💡 Hint
You must stop the container before pulling and restarting with new image.
Best Practice
expert
2:00remaining
Best practice for managing secrets in database containers for local development
Which approach is the best practice for handling database passwords in Docker containers during local development?
ALeave the password empty for convenience during development
BUse Docker secrets even in local development for passwords
CPass passwords via environment variables from a local .env file excluded from version control
DHardcode the password in the Dockerfile environment variables
Attempts:
2 left
💡 Hint
Consider security and convenience balance in local development.