Challenge - 5 Problems
Docker Deployment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when running Laravel inside Docker with this Dockerfile?
Consider this Dockerfile for a Laravel app. What will be the result when you build and run the container?
FROM php:8.1-fpm WORKDIR /var/www/html COPY . . RUN docker-php-ext-install pdo pdo_mysql CMD ["php-fpm"]
Laravel
FROM php:8.1-fpm WORKDIR /var/www/html COPY . . RUN docker-php-ext-install pdo pdo_mysql CMD ["php-fpm"]
Attempts:
2 left
💡 Hint
Think about what PHP-FPM does and what is missing to serve HTTP requests.
✗ Incorrect
This Dockerfile uses the official PHP-FPM image which runs PHP FastCGI Process Manager. It does not include a web server like Apache or Nginx. So while PHP runs, HTTP requests won't be served unless a web server is added.
📝 Syntax
intermediate2:00remaining
Which docker-compose.yml snippet correctly defines a Laravel app with MySQL service?
You want to run Laravel with a MySQL database using Docker Compose. Which snippet is correct?
Laravel
version: '3.8' services: app: build: . ports: - "8000:80" depends_on: - db db: image: mysql:8 environment: MYSQL_ROOT_PASSWORD: secret MYSQL_DATABASE: laravel MYSQL_USER: user MYSQL_PASSWORD: secret
Attempts:
2 left
💡 Hint
Check if the services and environment variables match Laravel and MySQL requirements.
✗ Incorrect
This docker-compose.yml correctly defines an app service built from the current directory and a MySQL 8 service with proper environment variables. Port 8000 is mapped for the app HTTP traffic. Volumes are recommended but not required.
🔧 Debug
advanced2:00remaining
Why does Laravel fail to connect to MySQL in this Docker setup?
Given this docker-compose.yml snippet:
Laravel inside the app container cannot connect to MySQL. Why?
services:
app:
build: .
environment:
DB_HOST: localhost
DB_DATABASE: laravel
DB_USERNAME: user
DB_PASSWORD: secret
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
MYSQL_USER: user
MYSQL_PASSWORD: secretLaravel inside the app container cannot connect to MySQL. Why?
Laravel
services:
app:
build: .
environment:
DB_HOST: localhost
DB_DATABASE: laravel
DB_USERNAME: user
DB_PASSWORD: secret
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
MYSQL_USER: user
MYSQL_PASSWORD: secretAttempts:
2 left
💡 Hint
Think about how Docker containers communicate by service name, not localhost.
✗ Incorrect
Inside Docker Compose, containers communicate using service names as hostnames. 'localhost' refers to the container itself, so Laravel cannot reach the MySQL container using 'localhost'. Using 'db' as DB_HOST fixes this.
❓ lifecycle
advanced2:00remaining
What happens if you run 'docker-compose down' in a Laravel Docker setup with volumes?
You have a Laravel app and MySQL running with Docker Compose. The MySQL service uses a named volume for data. What happens when you run 'docker-compose down'?
Laravel
version: '3.8' services: app: build: . db: image: mysql:8 volumes: - mysql_data:/var/lib/mysql volumes: mysql_data:
Attempts:
2 left
💡 Hint
Consider the difference between 'docker-compose down' and 'docker-compose down -v'.
✗ Incorrect
'docker-compose down' stops and removes containers and networks but preserves named volumes. To remove volumes, you must add the '-v' flag.
🧠 Conceptual
expert3:00remaining
Which is the best way to optimize Laravel Docker image size for production?
You want to deploy a Laravel app with Docker in production. Which approach best reduces the final image size while keeping functionality?
Attempts:
2 left
💡 Hint
Think about separating build environment from runtime environment.
✗ Incorrect
Multi-stage builds allow compiling and installing dependencies in a build stage, then copying only the necessary runtime files to a smaller base image. This reduces image size and attack surface.