-
Copy
.env.dist
to.env
:$ cp .env.dist .env
-
If you plan to use the default docker repository to pull the Docker’s images, you can keep the default values of the
PROJECT_NAMESPACE
andREPOSITORY_NAME
environment variables from the.env
file and skip this step. Otherwise you need to build your own images. You can do that with:$ ./bin/build
-
Start the container.
$ docker-compose up -d
-
Access your application via http://localhost/.
# Start containers.
$ docker-compose up -d
# Restart services.
$ docker-compose restart
# List containers.
$ docker-compose ps
# Start a terminal session for <container_name> (i.e: php).
$ docker-compose exec <container_name> /bin/bash
# View logs.
$ docker-compose logs
# List/remove network.
$ docker network [ ls | rm <network_name> ]
# List/remove volumes.
$ docker volume [ ls | rm <volume_name> ]
# Stop containers.
$ docker-compose stop
# Stop and remove containers. Any data which is not in a volume will be lost.
$ docker-compose down
By default docker-compose.yml
uses the latest
tag name of the php image which corresponds to php 7.1.
services:
php:
image: ${PROJECT_NAMESPACE}/${REPOSITORY_NAME}-php:latest
If you want a specific version of php, you can change it with one of those values: 5.6
, 7.0
or 7.1
. Example:
php:
image: ${PROJECT_NAMESPACE}/${REPOSITORY_NAME}-php:5.6
The default docker repository already provides the images for those php version. Otherwise you need to build them by yourself with:
$ ./bin/build
Edit docker-compose.yml
and add a new service definition:
services:
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8080:80"
environment:
PMA_HOST: mysql
networks:
- backend
Then phpmyadmin will be accessible to http://localhost:8080/
Place the composer.json
file that describes the dependencies of your project inside the app
folder, then install the defined dependencies through the php
container:
$ docker-compose run --rm php composer install
You can use Composer to ease the creation of a new symfony project:
$ rm -rf app/* && docker-compose run --rm -u $(id -u):$(id -g) php composer create-project symfony/framework-standard-edition .
As from Symfony3.2 you can use the environment variables into you service container configuration, using the %env(MYSQL_DATABASE)%
notation:
Composer will create a new Symfony Standard Edition application under the app/
directory.
A minimum configuration file to get your application running under Nginx is already provided from docker-skeleton-php
.
Remove the default.conf
file and rename symfony.conf.example
into symfony.conf
:
$ rm sites/default.conf
$ mv sites/symfony.conf.example sites/symfony.conf
Now remove the access check from app/web/app_dev.php
:
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
Warning: After you deploy to production, make sure that you cannot access the
app_dev.php
You can start the containers now:
$ docker-compose up -d
How can I use Symfony's console?
-
For Symfony 3:
$ docker-compose run --rm php php bin/console
-
For Symfony 2:
$ docker-compose run --rm php php app/console