
Prerequisites
Before you start, you need to have some certain prerequisites in place:
Installing Docker Docker Desktop. If you’re using up-to-date versions of Windows or Mac, install Docker Desktop and you’re done. If you are a Linux user, Docker packages are popular and usually included in your distribution’s repository. For example, installing it on Ubuntu or Debian is as easy as: $ apt-get update && apt-get install docker. Installing PHP Packages with Docker and Composer Written on October 13th, 2017 by Karl Hughes Package management is a method for importing code (often from open source libraries) and keeping dependencies up to date in a software development project.
- PHP 7.1.3+
- Local machine running the latest version of Docker.
Get Started
Let's create a Symfony project and then see how we can dockerize it using Docker.
Symfony Requirements
In this tutorial we will use Symfony 4. These are the technical requirements to run it:
- PHP version: 7.1.3 or higher
- PHP extensions: (all of them are installed and enabled by default in PHP 7+)
- Ctype
- iconv
- JSON
- PCRE
- Session
- SimpleXML
- Tokenizer
Step 1 - Install Symfony

Symfony utilizes Composer to manage its dependencies, similar to Laravel. So, before using Symfony, make sure you have Composer installed on your machine.
Install Composer
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. To a install it quickly, just open up a terminal and run this command:
Composer is multi-platform and it run equally well on Windows, Linux and macOS. Here you will get more information regarding how to install composer in each platform:
To make things simple, Symfony provides a tool to quickly check if your system meets these requirements. In addition, the tool provides recommendations if applicable. So run this command to install the tool:
Once you have fixed all the reported issues, uninstall the requirements checker to avoid leaking internal information about your application to visitors:
Step 2 - Create a Symfony Project
You can create a symfony skeleton project by issuing the Composer create-project
command in your terminal:
The project directory will contain the following folders:
- config: holds config files
- src: where we place our PHP code
- bin: contains executable files
- var: where automatically-created files are stored (cache, log)
- vendor: contains third-party libraries
- public: contains publicly accessible files
Then, to install all dependencies and run the project, you need to run the following commands:
You will see your Symfony server running on: http://127.0.0.1:8000
Congratulations, you’ve created a Symfony project!

Step 3 - Dockerize the Project
Setup Docker
Before creating a container for the Symfony application and shipping it off, you need to install Docker on your local machine. For learning purpose, you will install Docker Community Edition. Select your OS from the list below and follow the setup instructions:
Make the docker App image
The next stage to improve your docker php development workflow is adding a Dockerfile
to your project. The structure of a Dockerfile
can be considered a series of instructions on how to build your container/image.
Start the Dockerfile by creating an empty file named Dockerfile
in the root of your project. Then, complete each instruction according to the following example:
Building and Running the Container
Building the container is very straight forward once you have Docker and Docker Machine on your system. The following command will look for your Dockerfile
and download all the necessary layers required to get your container image running. Afterwards, it will run the instructions in the Dockerfile
and leave you with a container that is ready to start.
To build your php laravel docker container, you will use the docker build
command and provide a tag or a name for the container, so you can reference it later when you want to run it. The final part of the command tells Docker which directory to build from.
The final step is to run the container you have just built using Docker:
The command tells Docker to run the container and forward the exposed port 8000 to port 8000 on your local machine. After you run this command, you should be able to visit http://localhost:8000 in your browser.
You can see the Docker containers that are currently running on your system (along with their Container IDs) with:
To turn off your Docker container, run:
Push to cloud
1. Create your app
In order to install your docker php example, just create a new app via cli or admin panel and set a port to 8000.
2. Push your docker container
3. Set up resources
4. Logs and app status
5. Release your app
After to click on the release button, your php docker tutorial will be deployed, Just click on the generated URL and you will get your app running.
Now you can deploy your Symfony app without a massive build time.
Bonus 1: SSL certificate for HTTPS
It's already done for you. If you need to connect your custom domain, SSL certificate will be provided for it.
Bonus 2: Autoscaling
With autoscaling the app will be scaled up when CPU and RAM load goes up and scaled down when it goes down.
Now you can deploy your Symfony app without a massive build time.
Written on October 13th, 2017 by Karl HughesPackage management is a method for importing code (often from open sourcelibraries) and keeping dependencies up to date in a software developmentproject. In PHP, we have a couple ways to manage packages, but the dominantchoice for modern PHP development is Composer.
While you can install PHP and Composer on your local machine directly, in thistutorial we’ll use Docker, which allows us to run PHP and Composer scriptswithout configuring either on our system directly. If you haven’t already, youshould install Docker for your operatingsystem.
Creating a PHP Timer Script
We are going to write a PHP script that sleeps for between 1 and 3 seconds, thentells us how long it waited. It’s very simple using the PHP Timerpackage, but we’ll need toimport it.
composer.json
Create a new file called composer.json
and add the following to it:

This tells Composer about our dependencies — in this case, just one package —when we run the install command.
Installing the Dependencies
Ubuntu Install Composer
Next, we will install the dependencies using the official Composer Dockerimage:
Docker Install Composer Php Online
Let’s look at this docker command and see what’s going on:
docker run
is Docker’s command to run a command within a newcontainer. There are a lot ofoptions that you can pass in, so be sure to read the documentation.--rm
tells Docker to “remove” the container after the command is run.Alternatively, you can save the container and name it to run it again.-v $(pwd):/app
is telling Docker to mount avolume. You typicallypass in a path to a folder on your root directory, a colon, and then a path tothe folder in the container. Here we are mounting the current directory (alongwith thecomposer.json
file we created) into a container. This mounting goesboth ways, so we will also see the/vendor
folder created when Composer runs.composer/composer:latest
is the actual image we’re using for this container.This will install the packages for PHP 7, but Composer also has images for olderversions of PHP.install
is the Composer command that is going to be run. You can also doupdate
ordump-autoload
in this same manner.
Now all the dependencies are installed in a new /vendor
folder, but we stillhave to import them and write our PHP script.
The PHP Script
Our PHP script imports the dependencies that are included in Composer’svendor/autoload.php
file, starts a timer, waits between 1 and 3 seconds, thenoutputs the final time that the script took to run. This part of the tutorialworks the same way whether you use Docker or not. This file should be namedindex.php
:
Running the PHP Script
Finally, we just need to run the new PHP script we created in another Dockercontainer. This is covered in more detail in our tutorial on running PHP scriptsin Docker, but the final command should be:
Install Php
You should see either 1 second
, 2 seconds
, or 3 seconds
on your terminaloutput.
Docker Install Composer Php Download
Learn to build your first Dockerized PHP application.
In this book, PHP developers will learn everything they need to know to start building their applications on Docker, including:
- Installing dependencies using Composer.
- Getting data from a third-party API.
- Saving data to a MySQL database.
- Using a web framework (SlimPHP) for routing.
- Storing environmental variables securely.
- And much more!
You can buy this book on Leanpub today.