├── .gitignore ├── LICENSE ├── Readme.md ├── setup.sh └── src ├── .env.dockerizer.local ├── Dockerfile ├── docker-compose.yml ├── dockerize.sh └── nginx └── conf.d └── laravel.conf /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 transprime-research 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ### About Laravel Dockerizer 5 | You want to use docker and add it into your laravel project immediately? Add, yes add docker to your Laravel. And simply continue your development. 6 | 7 | ## First install 8 | 9 | - Clone the repository into your project 10 | > **SSH**: `git clone git@github.com:transprime-research/laravel-dockerizer.git` 11 | 12 | > **HTTP**: `git clone https://github.com/transprime-research/laravel-dockerizer.git` 13 | 14 | - Cd into `laravel-dockerizer` directory, and run the bash file `setup.sh` using any bash command that fits your os 15 | 16 | Common ones are 17 | 18 | - `bash setup.sh` 19 | - `sh setup.sh` 20 | - `./setup.sh` # This usually require execution permission 21 | 22 | After this `docker-compose.yml`, `Dockerfile`, and `dockerizer.sh` should already be moved to your project's directory. 23 | 24 | Then `cd ..` (back) into your project, and run bash command against `dockerizer.sh` e.g `sh dockerizer.sh`. 25 | 26 | After that go to `localhost:8070` 27 | 28 | > Feel free to delete `laravel-dockerizer` directory or leave it ;) 29 | 30 | #### Pro Hint: 31 | 32 | - You can also now run `docker-compose build` and `docker-compose up -d` but `dockerizer.sh` already packaged these commands for you. 33 | 34 | - You can also edit these files also and change the configurations. 35 | 36 | ## Helpful links 37 | 38 | Please refer to Docker Documenation at: https://docs.docker.com/ 39 | 40 | Extra resource: https://www.howtoforge.com/dockerizing-laravel-with-nginx-mysql-and-docker-compose/ 41 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | project_path=$1 4 | 5 | if [ "$project_path" ] 6 | then 7 | if [ -d "../$project_path" ] 8 | then 9 | echo path exist $project_path 10 | cp -vRT src/ ../$project_path/ 11 | fi 12 | fi 13 | 14 | if [ ! "$project_path"] & [ -f "../artisan" ] 15 | then 16 | echo "Laravel artisan exists" 17 | 18 | if [ "$(uname)" = "Darwin" ] 19 | then 20 | echo 'Running on Mac OS X' 21 | cp -vR src/ ../ 22 | fi 23 | 24 | if [ ! "$(uname)" = "Darwin" ] 25 | then 26 | cp -vRT src/ ../ 27 | echo 'Running on non Mac OS X' 28 | fi 29 | fi -------------------------------------------------------------------------------- /src/.env.dockerizer.local: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY=base64:VHn84+4kE9nObIz0BW6FqtcLPOWmHInZF3uALL3d4Wc= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=mysql 10 | DB_HOST=mysql 11 | DB_PORT=3306 12 | DB_DATABASE=laravel 13 | DB_USERNAME=laravel 14 | DB_PASSWORD=laravel 15 | 16 | BROADCAST_DRIVER=log 17 | CACHE_DRIVER=file 18 | QUEUE_CONNECTION=sync 19 | SESSION_DRIVER=file 20 | SESSION_LIFETIME=120 21 | 22 | REDIS_HOST=127.0.0.1 23 | REDIS_PASSWORD=null 24 | REDIS_PORT=6379 25 | 26 | MAIL_DRIVER=smtp 27 | MAIL_HOST=smtp.mailtrap.io 28 | MAIL_PORT=2525 29 | MAIL_USERNAME=null 30 | MAIL_PASSWORD=null 31 | MAIL_ENCRYPTION=null 32 | 33 | AWS_ACCESS_KEY_ID= 34 | AWS_SECRET_ACCESS_KEY= 35 | AWS_DEFAULT_REGION=us-east-1 36 | AWS_BUCKET= 37 | 38 | PUSHER_APP_ID= 39 | PUSHER_APP_KEY= 40 | PUSHER_APP_SECRET= 41 | PUSHER_APP_CLUSTER=mt1 42 | 43 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 44 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 45 | -------------------------------------------------------------------------------- /src/Dockerfile: -------------------------------------------------------------------------------- 1 | # Set master image 2 | # FROM php:7.2-fpm-alpine 3 | FROM php:7.4-fpm-alpine 4 | 5 | # Copy composer.lock and composer.json 6 | COPY composer.lock composer.json /var/www/html/ 7 | 8 | # Set working directory 9 | WORKDIR /var/www/html 10 | 11 | # Install Additional dependencies 12 | RUN apk update && apk add --no-cache \ 13 | build-base shadow vim curl \ 14 | php7 \ 15 | php7-fpm \ 16 | php7-common \ 17 | php7-pdo \ 18 | php7-pdo_mysql \ 19 | php7-mysqli \ 20 | php7-mcrypt \ 21 | php7-mbstring \ 22 | php7-xml \ 23 | php7-openssl \ 24 | php7-json \ 25 | php7-phar \ 26 | php7-zip \ 27 | php7-gd \ 28 | php7-dom \ 29 | php7-session \ 30 | php7-zlib 31 | 32 | # Add and Enable PHP-PDO Extenstions 33 | RUN docker-php-ext-install pdo pdo_mysql 34 | RUN docker-php-ext-enable pdo_mysql 35 | 36 | # Install PHP Composer 37 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 38 | 39 | # Remove Cache 40 | RUN rm -rf /var/cache/apk/* 41 | 42 | # Add UID '1000' to www-data 43 | RUN usermod -u 1000 www-data 44 | 45 | # Copy existing application directory permissions 46 | COPY --chown=www-data:www-data . /var/www/html 47 | 48 | # Change current user to www 49 | USER www-data 50 | 51 | # Expose port 9000 and start php-fpm server 52 | EXPOSE 9000 53 | CMD ["php-fpm"] -------------------------------------------------------------------------------- /src/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | app: 5 | build: 6 | context: . 7 | dockerfile: Dockerfile 8 | container_name: app 9 | env_file: 10 | - ./.env.dockerizer.local 11 | restart: unless-stopped 12 | tty: true 13 | working_dir: /var/www/html 14 | environment: 15 | SERVICE_TAGS: dev 16 | SERVICE_NAME: app 17 | volumes: 18 | - ./:/var/www/html 19 | networks: 20 | - laravel 21 | 22 | #Nginx Service 23 | nginx: 24 | image: nginx:alpine 25 | container_name: nginx 26 | restart: unless-stopped 27 | tty: true 28 | ports: 29 | - "8070:80" 30 | # - "443:443" 31 | volumes: 32 | - ./:/var/www/html 33 | - ./nginx/conf.d/:/etc/nginx/conf.d/ 34 | # - ./nginx/ssl/:/etc/nginx/ssl/ 35 | networks: 36 | - laravel 37 | 38 | #MySQL Service 39 | mysql: 40 | image: mysql:5.7.22 41 | container_name: mysql 42 | restart: unless-stopped 43 | tty: true 44 | ports: 45 | - "3306:3306" 46 | environment: 47 | MYSQL_DATABASE: laravel 48 | MYSQL_USER: laravel 49 | MYSQL_PASSWORD: laravel 50 | MYSQL_ROOT_PASSWORD: laravel 51 | SERVICE_TAGS: dev 52 | SERVICE_NAME: mysql 53 | volumes: 54 | - mysqldata:/var/lib/mysql/ 55 | networks: 56 | - laravel 57 | 58 | #Docker Networks 59 | networks: 60 | laravel: 61 | driver: bridge 62 | #Volumes 63 | volumes: 64 | mysqldata: 65 | driver: local 66 | -------------------------------------------------------------------------------- /src/dockerize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | docker-compose build 4 | 5 | docker-compose up -d --remove-orphans 6 | 7 | docker-compose exec app composer install 8 | -------------------------------------------------------------------------------- /src/nginx/conf.d/laravel.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | error_log /var/log/nginx/error.log; 5 | access_log /var/log/nginx/access.log; 6 | 7 | root /var/www/html/public; 8 | index index.php index.html; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php?$query_string; 12 | gzip_static on; 13 | } 14 | 15 | location ~ \.php$ { 16 | try_files $uri =404; 17 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 18 | fastcgi_pass app:9000; 19 | fastcgi_index index.php; 20 | include fastcgi_params; 21 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 22 | fastcgi_param PATH_INFO $fastcgi_path_info; 23 | } 24 | } --------------------------------------------------------------------------------