Ready to use docker-compose stack with php7 (php7-fpm), nginx and postgresql optimised for Symfony3 applications (with ELK & Redis)
##Disclaimer
- Nginx conf & docker-compose.yml assure your project is located in /var/www/ (if not make sure to change the .yml & .conf files)
- Redis & ELK are optional
##Step by step configuration ###Step 1 make sure docker and docker-compose are installed
###Step 2
- Replace every occurence of {PROJECT_NAME} by the name of you project
- Rename .conf/.site-conf/{PROJECT_NAME}.conf to the desired configuration name
- Replace {PROJECT_URL} by the desired url of your project.
- Edit DB_USER, DB_PASS, DB_NAME in .conf/.env/db.env
##Step 3 update your hosts file with the new url
sudo echo 127.0.0.1 {PROJECT_URL} www.{PROJECT_URL} >> /etc/hosts
###Step 4 Pull docker images
docker pull redis:alpine && docker pull willdurand/elk && docker pull php:7-fpm && docker pull nginx:latest && docker pull postgres:latest
###Step 5 go to /var/www/project_name & run docker-compose
docker-compose up -d
###Step 6 enjoy ! go to www.project_url (make sure your have something in the directory /var/www/{PROJECT_NAME}/web)
###Step 7 (optional) Add your ip of your host (seen from your php-fpm container) in web/config.php and web/app_dev.php (mine was 172.18.0.1)
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'172.18.0.1', //ip to add
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
If you don't know the ip to add :
var_dump($_SERVER['REMOTE_ADDR']);
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
###Useful commands
- List all active containers
docker ps
- List all the images available locally
docker images
- Open bash in the given docker container (use docker ps to see docker id):
docker exec -it {docker_id} bash
- Clear cache symfony :
docker exec -it $(docker ps -f name=php -q) php /var/www/{PROJECT_NAME}/bin/console cache:clear
- Use psql in postgresql container :
docker exec -it $(docker ps -f name=postgre -q) psql -U postgres
##Todo
- Test db container
- Use php7-fpm docker images with recommended extensions and Xdebug
##Special thanks User Thomas Letellier for help & support
User Ronan Guilloux for inspiration