Sponsored By: Password Angel - Share passwords, API keys, credentials and more with secure, single-use links.

Creating New Symfony Applications with Docker and the Symfony CLI

If you're like me and using docker to manage your development environment then using something like the Symfony CLI to create a new Symfony project won't work using the standard instructions because PHP, composer or some other dependency is not installed or up-to-date on your host machine.

To work around this for a recent project, I created a Symfony CLI Docker Image, built from the PHP image and installs composer & the symfony cli. You can get this image by running

docker pull chrisshennan/symfony-cli

Using this docker image you can follow the installation instructions and replace symfony with docker run chrisshennan/symfony (for the most part - see "Create your new Symfony application" for full instructions) and you will be able to set up a new application.

If you would prefer, you can build the image yourself using the instructions below.

Create the Dockerfile

FROM php:latest

RUN apt-get update

# Install composer (see
RUN php -r "copy('', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer

# Install symfony CLI (
RUN curl -1sLf '' | bash
RUN apt install symfony-cli -y

# Clear apt cache to reduce image size
RUN rm -rf /var/cache/apt/archives /var/lib/apt/lists

ENTRYPOINT ["/usr/bin/symfony"]

Build the docker image

docker build -t chrisshennan/symfony-cli .

Create your new Symfony application

# Create the project directory

# Create the symfony application inside the project directory
docker run --rm \
    -v ./ \
    -v ${HOME}/.gitconfig:/root/.gitconfig \
    -w /app \
    chrisshennan/symfony-cli new --webapp /app

Note: We're mounting your hosts global .gitconfig into the container via -v ${HOME}/.gitconfig:/root/.gitconfig as the Symfony command sets up the git repository and needs to know who you are (i.e. the git configuration values for and

This will output

* Creating a new Symfony project with Composer
  (running /usr/local/bin/composer create-project symfony/skeleton /app  --no-interaction)

* Setting up the project under Git version control
  (running git init /app)

  (running /usr/local/bin/composer require webapp --no-interaction)

 [OK] Your project is now ready in /app

Start the PHP Development Web Server

To test the Symfony application has been created and is ready for development, you can run the following command to start the PHP built-in webserver

docker run --rm -v -w /app -p 8888:80 php:latest bash -c "php -S -t public/"

and then open a browser and go to http://localhost:8888/ (Note: it's port 8888 and not 80). This should bring up the Symfony default webpage like the one shown below.

Symfony 7 Default Page


Enjoyed this article?

Thank you for reading this article! If you found the information valuable and enjoyed your time here, consider supporting my work by buying me a coffee. Your contribution helps fuel more content like this. Cheers to shared knowledge and caffeine-fueled inspiration!

Buy me a coffee

Originally published at

Subscribe to my newsletter...

... and receive the musings of an aspiring #indiehacker directly to your inbox once a month.

These musings will encompass a range of subjects such as Web Development, DevOps, Startups, Bootstrapping, #buildinpublic, SEO, personal opinions, and experiences.

I won't send you spam and you can unsubscribe at any time.