How to run Symfony in Docker for development?

To run Symfony in Docker for development, you can follow these steps:

  1. Install Docker on your machine if you haven't already.

  2. Create a new Symfony project by running the following command in your terminal:

    symfony new my_project_name --full
  3. Create a Dockerfile in the root directory of your Symfony project with the following content:

    FROM php:7.4.5 WORKDIR /app COPY . . RUN apt-get update && apt-get install -y git zip RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN composer install CMD ["php", "-S", "0.0.0.0:8000", "-t", "public"]
  4. Create a docker-compose.yml file in the root directory of your Symfony project with the following content:

    version: '3' services: app: build: . ports: - "8000:8000"
  5. Build and run the Docker container by running the following commands in your terminal:

    docker-compose build docker-compose up
  6. Access your Symfony application in a web browser by navigating to http://localhost:8000.

You can now start developing your Symfony application within the Docker container. Any changes you make to your Symfony project files will be automatically reflected in the running container.