Advertisement
Intermediate PHP, PHP with Docker

How does Docker Compose let you define and run a complete multi container PHP application setup, including a web server, PHP-FPM, and a database, together?

Short answer

Docker Compose lets you define an entire multi container application, such as an Nginx web server, a PHP-FPM application container, and a MySQL database container, all within a single YAML configuration file, specifying how they should be networked together and what environment…

Save PHP mock interview
Advertisement
AModel answer
Docker Compose lets you define an entire multi container application, such as an Nginx web server, a PHP-FPM application container, and a MySQL database container, all within a single YAML configuration file, specifying how they should be networked together and what environment variables or volumes each service needs, letting you start your complete local development environment with a single command rather than manually configuring and starting each individual container yourself.
services:
  app:
    build: .
    volumes:
      - .:/var/www/html
  db:
    image: mysql:8.0
    environment:
      MYSQL_DATABASE: myapp
Real-world example
A development team defines their entire local environment, including PHP-FPM, Nginx, and MySQL, in a single docker-compose.yml file, letting any new team member get a fully working local development environment running with a single docker compose up command.
Likely follow-ups
  • How do containers defined in the same Docker Compose file communicate with each other by name?
  • What is the purpose of mounting a volume for local development compared to production?
Related topics