To run Symfony in Docker for development, you can follow these steps:
Install Docker on your machine if you haven't already.
Create a new Symfony project by running the following command in your terminal:
symfony new my_project_name --full
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"]
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"
Build and run the Docker container by running the following commands in your terminal:
docker-compose build
docker-compose up
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.