├── .editorconfig ├── .gitignore ├── LICENSE ├── Makefile ├── README.dist.md ├── README.md ├── composer.json ├── dev.yml ├── docker-compose.yml ├── docker └── web │ ├── backend │ └── Dockerfile │ └── frontend │ ├── Dockerfile │ └── default.conf └── prod.yml /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [Makefile] 16 | indent_style = tab 17 | indent_size = 4 18 | 19 | [*.yml] 20 | indent_size = 2 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /web 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Jérôme Gamez 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := help 2 | 3 | build: ## Builds docker images from the current project files 4 | docker-compose build 5 | 6 | up-dev: ## Creates and starts the docker containers with development settings 7 | docker-compose -f docker-compose.yml -f dev.yml up -d 8 | docker-compose ps 9 | 10 | up-prod: build ## Creates and starts the docker containers with production settings 11 | docker-compose -f docker-compose.yml -f prod.yml up -d 12 | docker-compose ps 13 | 14 | down: ## Stops and removes the docker containers 15 | docker-compose down 16 | 17 | help: 18 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}' 19 | -------------------------------------------------------------------------------- /README.dist.md: -------------------------------------------------------------------------------- 1 | # A Slim Framework application 2 | 3 | ## Requirements 4 | 5 | - [Docker Engine](https://docs.docker.com/engine/installation/) and 6 | [Docker Compose](https://docs.docker.com/compose/) 7 | - [Composer](https://getcomposer.org/) installed in your global path 8 | 9 | ## Installation 10 | 11 | ```bash 12 | $ cd dev 13 | $ composer install 14 | ``` 15 | 16 | ## Images and Containers 17 | 18 | The images for the application containers are built from the Dockerfiles in 19 | the `docker` directory. 20 | 21 | - The [backend image](docker/web/backend/Dockerfile) extends the official 22 | [`php-fpm`](https://hub.docker.com/_/php/) image. 23 | - The [frontend image](docker/web/frontend/Dockerfile) extends the official 24 | [`nginx`](https://hub.docker.com/_/nginx/) image. 25 | 26 | ## Helpers 27 | 28 | The Makefile simplifies some basic tasks: 29 | 30 | - `make build` builds new Docker images with the current project files being copied 31 | into the images. 32 | - `make up-dev` will add the settings from [`dev.yml`](dev.yml) to the 33 | default configuration and start the application with the `web` directory being 34 | mounted into the containers. 35 | - `make up-prod` will add the settings from [`prod.yml`](prod.yml) to the 36 | default configuration and start the application 37 | - `make down` will stop the application 38 | 39 | Execute `make` or `make help` from the project root to show all available tasks. 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Slim Framework Skeleton for Docker 2 | 3 | A dockerized [Slim Framework skeleton](https://github.com/slimphp/Slim-Skeleton) application as 4 | a starting point for new [Slim Framework](http://www.slimframework.com) projects. 5 | 6 | ## Requirements 7 | 8 | - [Docker Engine](https://docs.docker.com/engine/installation/) and 9 | [Docker Compose](https://docs.docker.com/compose/) 10 | - [Composer](https://getcomposer.org/) installed in your global path 11 | 12 | ## Installation 13 | 14 | Create a new project from this starter with 15 | 16 | ```bash 17 | $ composer create-project kreait/slim-docker target-directory 18 | ``` 19 | 20 | The actual Slim Framework application will be located in `target-directory/web`. 21 | 22 | Then, start up the dockerized application: 23 | 24 | ```bash 25 | $ cd target-directory 26 | $ docker-compose up 27 | ``` 28 | 29 | ## Images and Containers 30 | 31 | The images for the application containers are built from the Dockerfiles in 32 | the `docker` directory so that you can modify them as needed for your 33 | application. 34 | 35 | - The [backend image](docker/web/backend/Dockerfile) extends the official 36 | [`php-fpm`](https://hub.docker.com/_/php/) image. 37 | - The [frontend image](docker/web/frontend/Dockerfile) extends the official 38 | [`nginx`](https://hub.docker.com/_/nginx/) image. 39 | 40 | ## Helpers 41 | 42 | The starter includes a Makefile to simplify the basic tasks: 43 | 44 | - `make build` builds new Docker images with the current project files being copied 45 | into the images. 46 | - `make up-dev` will add the settings from [`dev.yml`](dev.yml) to the 47 | default configuration and start the application with the `web` directory being 48 | mounted into the containers. 49 | - `make up-prod` will add the settings from [`prod.yml`](prod.yml) to the 50 | default configuration and start the application 51 | - `make down` will stop the application 52 | 53 | Execute `make` or `make help` from the project root to show all available tasks. 54 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kreait/slim-docker", 3 | "description": "Starter for a dockerized Slim Framework application", 4 | "keywords": ["framework", "slim", "docker"], 5 | "homepage": "https://github.com/kreait/slim-php-docker-starter", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Jérôme Gamez", 10 | "email": "jerome@gamez.name", 11 | "homepage": "https://www.gamez.name" 12 | } 13 | ], 14 | "scripts": { 15 | "post-root-package-install": [ 16 | "composer create-project slim/slim-skeleton web", 17 | "mv README.dist.md README.md", 18 | "rm .gitignore .editorconfig composer.json LICENSE" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dev.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | web-frontend: 5 | volumes: 6 | - ./web/public:/var/www/html/public 7 | 8 | web-backend: 9 | volumes: 10 | - ./web:/var/www/html 11 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | web-frontend: 5 | build: 6 | context: . 7 | dockerfile: ./docker/web/frontend/Dockerfile 8 | ports: 9 | - 80 10 | depends_on: 11 | - web-backend 12 | 13 | 14 | web-backend: 15 | build: 16 | context: . 17 | dockerfile: ./docker/web/backend/Dockerfile 18 | 19 | -------------------------------------------------------------------------------- /docker/web/backend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.0-fpm-alpine 2 | 3 | COPY web /var/www/html 4 | 5 | RUN rm -rf /var/www/html/logs/* \ 6 | && chown -R www-data:www-data /var/www/html 7 | 8 | -------------------------------------------------------------------------------- /docker/web/frontend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:alpine 2 | 3 | COPY docker/web/frontend/default.conf /etc/nginx/conf.d/default.conf 4 | COPY web/public /var/www/html/public 5 | -------------------------------------------------------------------------------- /docker/web/frontend/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | server_name _; 5 | 6 | index index.html index.php; 7 | root /var/www/html/public; 8 | 9 | location / { 10 | try_files $uri $uri/ /index.php$is_args$args; 11 | } 12 | 13 | location ~ \.php$ { 14 | try_files $uri =404; 15 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 16 | include fastcgi_params; 17 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 18 | # fastcgi_param SCRIPT_NAME $fastcgi_script_name; 19 | fastcgi_index index.php; 20 | fastcgi_pass web-backend:9000; 21 | } 22 | 23 | location ~ /\. { 24 | log_not_found off; 25 | deny all; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /prod.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | web-frontend: 5 | restart: always 6 | ports: 7 | - 80:80 8 | 9 | web-backend: 10 | restart: always 11 | --------------------------------------------------------------------------------