0
0
Laravelframework~20 mins

Docker deployment in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Deployment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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"]
AThe container runs PHP-FPM serving the Laravel app, but no web server is included so no HTTP requests are handled.
BThe container runs a full Apache server serving the Laravel app out of the box.
CThe container fails to build because pdo_mysql extension is not available for PHP 8.1.
DThe container runs but Laravel will not connect to the database because no database service is included.
Attempts:
2 left
💡 Hint
Think about what PHP-FPM does and what is missing to serve HTTP requests.
📝 Syntax
intermediate
2: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
AThe app service should expose port 3306 for MySQL, not 8000.
BThe snippet is missing volumes for persistent MySQL data, so data will be lost on restart.
CThe snippet is correct and will start Laravel app on port 8000 with MySQL database.
DThe environment variables for MySQL are incorrect; MYSQL_USER is not valid.
Attempts:
2 left
💡 Hint
Check if the services and environment variables match Laravel and MySQL requirements.
🔧 Debug
advanced
2:00remaining
Why does Laravel fail to connect to MySQL in this Docker setup?
Given this docker-compose.yml snippet:
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: secret

Laravel 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: secret
ADB_HOST should be 'db' not 'localhost' because containers have separate networks.
BThe MySQL image version 8 is incompatible with Laravel's database driver.
CThe environment variables must be set in a .env file, not in docker-compose.yml.
DThe app container needs to expose port 3306 to connect to MySQL.
Attempts:
2 left
💡 Hint
Think about how Docker containers communicate by service name, not localhost.
lifecycle
advanced
2: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:
AThe command fails because volumes cannot be used with 'docker-compose down'.
BThe containers and the MySQL data volume are deleted, losing all database data.
COnly the app container is removed; the db container and volume remain running.
DThe containers stop and are removed, but the MySQL data volume remains intact.
Attempts:
2 left
💡 Hint
Consider the difference between 'docker-compose down' and 'docker-compose down -v'.
🧠 Conceptual
expert
3: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?
AUse a single Dockerfile with all build tools and runtime in one image to avoid complexity.
BUse a multi-stage Dockerfile: build assets and dependencies in one stage, then copy only needed files to a smaller PHP runtime image.
CUse the official php:8.1-fpm image and install all composer dependencies and node modules inside it directly.
DUse Alpine Linux base image and install all Laravel dependencies manually to minimize size.
Attempts:
2 left
💡 Hint
Think about separating build environment from runtime environment.