This set of files gives you a nice little environment to work with a symfony 3 project using docker-compose.
Copy all four files to the root of your project:
- docker-compose.yml: describes the available services
- Dockerfile: builds the php backend service
- nginx.conf: configuration for nginx to serve from the backend service
- .env: configuration information for each of the services in the docker-compose
The docker-compose file describes four services:
- web: an nginx service configured with the
nginx.conf
file - backend: a php service with some good development defaults installed
- database: a mysql service that can be configured using the .env file
- email: an instance of mailhog, a web service that can be used to test sending emails from your application
$ docker-compose up -d
Once the services have all started you will have two addresses set up:
http://0.0.0.0:8080/ - the symfony project, if you get a message saying: "You are not allowed to access this file."
then you can fix this with a small change to the app_dev.php
file.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
change to:
if (
getenv('APP_ENVIRONMENT') !== 'dev' &&
(
isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
)
) {
http://0.0.0.0:8025/ - the web inteface for the email service, give it a test now by running the following:
$ docker-compose run backend sendmail -S email:1025 someone@nowhere <<'EOF'
Hey there\!
EOF
$ docker-compose run backend composer install
When symfony kicks in and asks for database credentials, just use the details you have in the .env
file.
$ docker-compose run backend bin/console <command>
Note that console commands will not work until your parameters.yml
file has been set up.