Setup Docker Machine for Symfony Development

If you need a development environment for Symfony, hosted by Docker, you can use the fazy/apache-symfony docker image to start with, then extend it to your need.

In your Symfony project's folder add the Dockerfile and docker-compose.yml files.

In the first one, we added mysql and composer, then we used the docker-compose.yml file to mount a local volume to the docker container with file sync.

This way you can code on your machine and test in the docker environment.

The Dockerfile:
[crayon-5e26ee0f91a73978298668/]
The docker-compose.yml file:
[crayon-5e26ee0f91a83485276438/]
To build the Docker container use:

[crayon-5e26ee0f91a89205104470-i/]

To start it when it's down just remove the --build parameter:

[crayon-5e26ee0f91a8f340388397-i/]

Once is running, you can view it's ID by running:

[crayon-5e26ee0f91a94020264103-i/]

Now grab the first 3 characters from the id and use them in the next command to be able to log in the running container:

[crayon-5e26ee0f91a99565436152-i/]

Finnaly, to access the Symfony project in your browser, go to http://localhost:8080/app_dev.php and have fun!