├── .gitignore ├── README.md ├── docker-compose.yml └── docker ├── nginx ├── Dockerfile ├── nginx.conf └── symfony.conf └── php ├── Dockerfile ├── php-fpm.conf └── php.ini /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .fleet 3 | .DS_Store 4 | **/.DS_Store 5 | ###> symfony/framework-bundle ### 6 | app/.env 7 | app/public/bundles/ 8 | app/var/ 9 | app/vendor/ 10 | ###< symfony/framework-bundle ### 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Symfony 6 Docker-Development-Stack 2 | This is a lightweight stack based on Alpine Linux for running Symfony 6 into Docker containers using docker compose. 3 | 4 | ### Container 5 | | name | contains | port | 6 | |---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------| 7 | | php | [php-fpm](https://hub.docker.com/_/php) 8.2, [composer](https://getcomposer.org/) 2.4, [yarn](https://yarnpkg.com/lang/en/) 1.22, [node.js](https://nodejs.org/en/) 16.17 | 9000 | 8 | | nginx | [nginx](https://hub.docker.com/_/nginx) 1.23 | 80 | 9 | | mongo | [mongoDB](https://hub.docker.com/_/mongo) 6.0 | 27017 | 10 | 11 | ### Installing 12 | run docker and connect to container: 13 | ``` 14 | docker compose up -d 15 | ``` 16 | ``` 17 | docker compose exec php sh 18 | ``` 19 | 20 | install the latest version of [Symfony](http://symfony.com/doc/current/setup.html) via composer: 21 | ``` 22 | # traditional web application: 23 | composer create-project symfony/website-skeleton . 24 | ``` 25 | or 26 | ``` 27 | # microservice, console application or API: 28 | composer create-project symfony/skeleton . 29 | ``` 30 | 31 | ### Ready up 32 | open [localhost](http://localhost/) in your browser 33 | 34 | ### Reference links 35 | https://github.com/mlocati/docker-php-extension-installer \ 36 | https://github.com/denji/nginx-tuning 37 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | php: 4 | build: './docker/php' 5 | ports: ['9000:9000'] 6 | volumes: ['./app/:/var/www/app:cached'] 7 | nginx: 8 | build: './docker/nginx' 9 | ports: ['80:80'] 10 | volumes: ['./app/:/var/www/app:cached'] 11 | mongo: 12 | image: mongo 13 | environment: 14 | MONGO_INITDB_ROOT_USERNAME: root 15 | MONGO_INITDB_ROOT_PASSWORD: password -------------------------------------------------------------------------------- /docker/nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:alpine 2 | 3 | ADD nginx.conf /etc/nginx/ 4 | ADD symfony.conf /etc/nginx/conf.d/default.conf 5 | 6 | EXPOSE 80 7 | 8 | CMD ["nginx"] -------------------------------------------------------------------------------- /docker/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | user nobody; 2 | worker_processes auto; 3 | pid /run/nginx.pid; 4 | 5 | events { 6 | worker_connections 4000; 7 | multi_accept on; 8 | use epoll; 9 | } 10 | 11 | http { 12 | server_tokens off; 13 | sendfile on; 14 | tcp_nopush on; 15 | tcp_nodelay on; 16 | keepalive_timeout 30; 17 | types_hash_max_size 2048; 18 | include /etc/nginx/mime.types; 19 | default_type application/octet-stream; 20 | access_log off; 21 | error_log off; 22 | gzip on; 23 | gzip_min_length 10240; 24 | gzip_comp_level 1; 25 | gzip_vary on; 26 | gzip_disable msie6; 27 | gzip_proxied expired no-cache no-store private auth; 28 | gzip_types 29 | text/css 30 | text/javascript 31 | text/xml 32 | text/plain 33 | text/x-component 34 | application/javascript 35 | application/x-javascript 36 | application/json 37 | application/xml 38 | application/rss+xml 39 | application/atom+xml 40 | font/truetype 41 | font/opentype 42 | application/vnd.ms-fontobject 43 | image/svg+xml; 44 | include /etc/nginx/conf.d/*.conf; 45 | include /etc/nginx/sites-enabled/*; 46 | reset_timedout_connection on; 47 | open_file_cache max=200000 inactive=20s; 48 | open_file_cache_valid 30s; 49 | open_file_cache_min_uses 2; 50 | open_file_cache_errors on; 51 | client_body_temp_path /tmp 1 2; 52 | client_body_buffer_size 256k; 53 | client_body_in_file_only off; 54 | } 55 | 56 | daemon off; -------------------------------------------------------------------------------- /docker/nginx/symfony.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | root /var/www/app/public; 4 | 5 | location / { 6 | try_files $uri /index.php$is_args$args; 7 | } 8 | 9 | location ~ ^/.+\.php(/|$) { 10 | fastcgi_pass php:9000; 11 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 12 | include fastcgi_params; 13 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 14 | fastcgi_param DOCUMENT_ROOT $realpath_root; 15 | internal; 16 | } 17 | 18 | location ~ \.php$ { 19 | return 404; 20 | } 21 | 22 | error_log /var/log/nginx/error.log; 23 | access_log /var/log/nginx/access.log; 24 | } -------------------------------------------------------------------------------- /docker/php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.2-fpm-alpine3.17 2 | 3 | RUN apk add --update nodejs npm yarn 4 | 5 | ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ 6 | RUN chmod +x /usr/local/bin/install-php-extensions && \ 7 | install-php-extensions apcu intl mongodb-stable opcache pcov 8 | 9 | RUN wget https://getcomposer.org/installer -O - | php -- --install-dir=/usr/local/bin --filename=composer 10 | 11 | ADD php.ini /usr/local/etc/php/php.ini 12 | ADD php-fpm.conf /usr/local/etc/php-fpm.conf 13 | 14 | WORKDIR /var/www/app 15 | 16 | EXPOSE 9000 17 | 18 | CMD ["php-fpm", "-F", "-R"] 19 | -------------------------------------------------------------------------------- /docker/php/php-fpm.conf: -------------------------------------------------------------------------------- 1 | [app] 2 | user=nobody 3 | group=nobody 4 | listen=0.0.0.0:9000 5 | pm=dynamic 6 | pm.max_children=20 7 | pm.start_servers=2 8 | pm.min_spare_servers=1 9 | pm.max_spare_servers=3 10 | catch_workers_output=yes -------------------------------------------------------------------------------- /docker/php/php.ini: -------------------------------------------------------------------------------- 1 | date.timezone=Europe/Berlin 2 | memory_limit=-1 3 | upload_max_filesize=20M 4 | post_max_size=30M 5 | opcache.jit_buffer_size=100M 6 | opcache.jit=1235 7 | opcache.enable_cli=0 8 | opcache.enable=1 9 | opcache.revalidate_freq=0 10 | opcache.validate_timestamps=1 11 | opcache.max_accelerated_files=50000 12 | opcache.memory_consumption=192 13 | opcache.max_wasted_percentage=10 14 | opcache.interned_strings_buffer=16 15 | opcache.fast_shutdown=1 16 | --------------------------------------------------------------------------------