DEV Community

Anthony Gilbert
Anthony Gilbert

Posted on

How to set up Symfony & then Dockerize it.

In this post we are going to be setting up a Symfony Docker environment. If you don't know what Symfony is, it's a PHP framework.

To get started we will install PHP, in this example we will be using PHP version 7.3. To do this you can install by typing the following:
brew install php

After install PHP we need to install composer, which is the PHP package manager. To do this we can copy-paste the following into the terminal. Code

You can run the following command to check if your system meets the Symfony requirements. symfony check:requirements

To create our Symfony project we will run the following command. symfony new my_project_name --full

Now to start our web server, we will run this command. symfony server:start, now your web server should be running on default port, 8000.

Now that we have our default application built, we need to install Docker. To do this you can run the following command in your terminal: brew install docker or visit the Docker website and download the executable.

Now we need to add a Dockerfile to the root of our project. You can do this by typing touch Dockerfile.

After creating your Dockerfile you will need to paste the following code into your Dockerfile. Code


To build our php Symfony docker container, we will use the docker build command and provide a tag or a name for the container, so we can reference it later when we want to run it. The final part of the command tells Docker which directory to build from.

docker build -t symfony-tutorial .

After running the build command, you need to create the image. To do this you need to type the following: docker build -t symfony-tutorial . You can make sure that the image has been created by typing docker images into the terminal.

Now that the docker image has been created, you can run your docker image and upon doing so, it will start the web server.
Here is how you do it: docker build -t symfony-tutorial .

Now your docker environment is running on port 8000!!

Happy coding!!


Top comments (0)