Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Last active March 23, 2019 09:06
Show Gist options
  • Save tarlepp/c7a193c5d01c6bb1356af1d2eb1047f6 to your computer and use it in GitHub Desktop.
Save tarlepp/c7a193c5d01c6bb1356af1d2eb1047f6 to your computer and use it in GitHub Desktop.
docker-compose setup for Symfony application with MySQL, PHP-FPM and Nginx + extra docker-sync for osx users - for Windows users there isn't real solution yet...
#
# For osx users, see http://docker-sync.io/
# this file should NOT be added to your VCS, only purpose of this is to override those volumes with docker-sync.yml config
#
# Also note that I'm not sure if this a correct setup - because I don't use osx - but docker-sync docs should get you the right track
#
version: '3'
services:
php:
volumes:
- backend-code:/app:cached
nginx:
volumes:
- backend-code:/app:cached
version: '3'
services:
php:
build:
context: .
dockerfile: ./Dockerfile_dev
command: php-fpm
#environment:
#APP_ENV=dev|test|prod
#APP_DEBUG=1|0
#APP_SECRET=8822e9bb81605a603006c9260793d983
#APPLICATION_CONFIG: /app/secrets/application.json
ports:
- 9000:9000
volumes:
- ./:/app:cached
nginx:
build:
context: ./docker/nginx/
ports:
- 8000:80
volumes:
- ./:/app:cached
mysql:
build:
context: ./docker/mysql/
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- 3310:3306
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
#!/bin/bash
set -e
#
# If we're starting web-server we need to do following:
# 1) Ensure that /app/var directory exists
# 2) Install all dependencies
# 3) Generate JWT encryption keys + allow webserver to read this file
# 4) Clear caches from dev and prod environments
# 5) Create database if it not exists yet
# 6) Run possible migrations, so that database is always up to date
# 7) Install public assets
# 8) Ensure that _all_ files have "correct" permissions
#
# Note that all the chmod stuff is for users who are using docker-compose within Linux environment. More info in link
# below:
# https://jtreminio.com/blog/running-docker-containers-as-current-host-user/
#
# Step 1
mkdir -p /app/var
# Step 2
curl -sS https://getcomposer.org/installer | php
php -d memory_limit=-1 composer.phar install --ansi
# Step 3
make generate-jwt-keys
chmod 644 /app/config/jwt/private.pem
# Step 4
php /app/bin/console cache:clear
# Step 5
php /app/bin/console doctrine:database:create --if-not-exists --no-interaction
# Step 6
php /app/bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
# Step 7
php /app/bin/console assets:install --symlink --relative --no-interaction
# Step 8
chmod -R o+s+w /app
exec "$@"
#
# For osx users, see http://docker-sync.io/
# this file should be added to your VCS
#
version: '2'
syncs:
backend-code:
src: ./
FROM php:7.2.13-fpm
RUN apt-get update \
&& apt-get install -y \
zlib1g-dev libxml2-dev \
nano vim git unzip jq \
&& rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install -j$(nproc) \
bcmath \
pdo \
pdo_mysql \
zip
ENV COMPOSER_ALLOW_SUPERUSER 1
WORKDIR /app
ADD . .
RUN chmod +x bin/console
RUN chmod +x docker-entrypoint-dev.sh
EXPOSE 9000
ENTRYPOINT ["/app/docker-entrypoint-dev.sh"]
FROM mysql:5.7
ADD mysql_custom.cnf /etc/mysql/conf.d/mysql_custom.cnf
RUN chmod 644 /etc/mysql/conf.d/mysql_custom.cnf
server {
server_name app.localhost;
root /app/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
location ~* \.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
disable_symlinks off;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 512k;
fastcgi_busy_buffers_size 512k;
error_log /var/log/nginx/app_error.log;
access_log /var/log/nginx/app_access.log;
}
FROM nginx:latest
ADD nginx.conf /etc/nginx/conf.d/default.conf
ADD php-upstream.conf /etc/nginx/conf.d/upstream.conf
RUN usermod -u 1000 www-data
upstream php-upstream {
server php:9000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment