{"id":15662823,"url":"https://github.com/garutilorenzo/laravel-docker","last_synced_at":"2025-05-06T01:52:01.503Z","repository":{"id":65384267,"uuid":"342511125","full_name":"garutilorenzo/laravel-docker","owner":"garutilorenzo","description":"Full stack (LEMP) Laravel environment for dev and production use","archived":false,"fork":false,"pushed_at":"2023-10-29T17:17:40.000Z","size":66,"stargazers_count":21,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T01:12:37.483Z","etag":null,"topics":["docker","laravel","laravel-docker","laravel-framework","lemp-stack","letsencrypt","nginx","php7","php8","ssl-certificates"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garutilorenzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-26T08:30:21.000Z","updated_at":"2024-08-01T17:17:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"08d38fc1-eb0e-4917-af08-8e1af23f7748","html_url":"https://github.com/garutilorenzo/laravel-docker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Flaravel-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Flaravel-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Flaravel-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Flaravel-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garutilorenzo","download_url":"https://codeload.github.com/garutilorenzo/laravel-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252606924,"owners_count":21775413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","laravel","laravel-docker","laravel-framework","lemp-stack","letsencrypt","nginx","php7","php8","ssl-certificates"],"created_at":"2024-10-03T13:34:37.904Z","updated_at":"2025-05-06T01:52:01.466Z","avatar_url":"https://github.com/garutilorenzo.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-docker\n\n[![Laravel CI](https://github.com/garutilorenzo/laravel-docker/actions/workflows/ci.yml/badge.svg)](https://github.com/garutilorenzo/laravel-docker/actions/workflows/ci.yml)\n[![GitHub issues](https://img.shields.io/github/issues/garutilorenzo/laravel-docker)](https://github.com/garutilorenzo/laravel-docker/issues)\n![GitHub](https://img.shields.io/github/license/garutilorenzo/laravel-docker)\n[![GitHub forks](https://img.shields.io/github/forks/garutilorenzo/laravel-docker)](https://github.com/garutilorenzo/laravel-docker/network)\n[![GitHub stars](https://img.shields.io/github/stars/garutilorenzo/laravel-docker)](https://github.com/garutilorenzo/laravel-docker/stargazers)\n\n![Laravel Logo](https://garutilorenzo.github.io/images/laravel.png)\n\n### How to use this repository\n\n#### Build the images (optional)\n\nIn the directory [build-env-files](build-env-files/) you will find the build environment variables for:\n\n* php-fpm\n* alpine\n* ubuntu\n\nand for each base image you can build the final image with: php 8, php 7.4 and php 7.3.\nOn each *php version* subdir you will find two *build env files* one for MySQL and one for PgSQL\n\nTo build the images from scratch you can run the following command:\n\n```console\ndocker-compose --env-file build-env-files/php-fpm/8/.env-pgsql -f build-phpfpm.yml build # --pull \u003c- Use '--pull' if you want to update the base image \n```\n\nIn this case the final image will be tagged with *localbuild/laravel-docker:php80-pgsql*, you can then push the newly builded image in your registry.\n\nThe supported build variables are:\n\n| Var   | Desc |\n| -------         | ----------- |\n| `LARAVEL_VERSION`    | Laravel version to be included in the builded image |\n| `DOCKER_IMAGE_VERSION`    | PHP base image version to use |\n| `COMPOSER_VERSION`    | Composer version to use |\n| `PDO`    | PDO to install, pdo_mysql or pdo_pgsql |\n| `PGSQL_DEP`    | Extra dependency fo Postgresql (optional, required for pgsql images)|\n\nSpecific build variables needed only for Ubuntu:\n\n| Var   | Desc |\n| -------         | ----------- |\n| `PHP_VERSION`    | Version of php to use |\n| `PHP_SHA256`    | SHA256 signature of the PHP package |\n| `GPG_KEYS`    | GPG keys of the PHP package |\n\nThere are a couple of \"hard coded\" variables inside the Dockerfile.\nThe variables are:\n\n* TZ: this variable set the timezone\n* LANG, LANGUAGE, LC_ALL: these variable set the locale of the container\n\nAlso to adjust the locale you have to modify this line \"sed -i -e 's/# it_IT.UTF-8 UTF-8/it_IT.UTF-8 UTF-8/' /etc/locale.gen\" with the locale you need.\n\n#### Bring up test or prod env\n\nThere are 2 differente docker-compose.yml:\n\n* docker-compose.yml-dev: Test environment\n* docker-compose.yml-prod: Production environment\n\nOther configurations files:\n\n* .env files contain variables used by docker-compose.yml, adjust with your personal settings.\n* config directory contains nginx configurations (only for prod environment). Adjust domain with your own domain\n* init_letsencrypt.sh (optional): initializes a custom ssl certificate used by nginx on the very first initlialization of the prod enviroment\n\n### Variables\n\nLaravel container accepts the following env variables:\n\n| Var   | Desc |\n| -------         | ----------- |\n| `LARAVEL_DB_HOST`    | MySQL or Postgresql host |\n| `FORCE_MIGRATE`    | Tells Laravel to run php artisan migrate --force at startup |\n| `FORCE_COMPOSER_UPDATE`    | Tells Laravel to run composer update at startup |\n| `CONTAINER_ROLE`    | Role of the laravel container, valid values are: queue, scheduler, app (default) |\n| `QUEUE_NAME`    | Name of the queue, required if the container is launched with CONTAINER_ROLE=queue |\n\nMySQL variables:\n\n| Var   | Desc |\n| -------         | ----------- |\n| `MYSQL_USER`    | MySQL user  |\n| `MYSQL_PASSWORD`    | MySQL password |\n| `MYSQL_DATABASE`    | MySQL database |\n\nPgSQL variables:\n\n| Var   | Desc |\n| -------         | ----------- |\n| `PGSQL_USER`    | Postgresql user |\n| `PGSQL_PASSWORD`    | Postgresql password |\n| `PGSQL_DB`    | Postgresql password |\n\n### Setup test or prod env\n\nFor testing purposes copy docer-compose.yml-dev in docker-compose.yml, fire up the enviromnent with:\n\n```console\ndocker-compose up -d\n```\n\nLaravel will be exposed on port 3000 (localhost)\n\nFor production enviroment copy docer-compose.yml-prod in docker-compose.yml.\n\nAdjust domain name in config/nginx/conf.d/example.conf (rename the file with appropriate name)\nFire up the enviromnent with:\n\n```console\ndocker-compose up -d\n```\n\nNginx will be exposed on port 80 and 443 of your host\n\n### Queue and Scheduler containers\n\nYou can run the laravel container as:\n\n* app. Run laravel to expose http applications (default)\n* queue container. More details [here](https://laravel.com/docs/8.x/queues)\n* scheduler container. More details [here](https://laravel.com/docs/8.x/scheduling#running-the-scheduler)\n\nAn example of running laravel container as queue container is:\n\n```yaml\nqueue_default:\n    image: garutilorenzo/laravel:php74-pgsql\n    build:\n      context: laravel/\n    container_name: queue_default\n    volumes:\n      - ${LARAVEL_DATA_DIR:-./laravel-project}:/var/www/html\n    environment:\n      - MYSQL_USER=${LARAVEL_DB_USER:-app}\n      - MYSQL_PASSWORD=${LARAVEL_DB_USER:-password}\n      - MYSQL_DATABASE=${LARAVEL_DB_NAME:-laravel}\n      - LARAVEL_DB_HOST=${LARAVEL_DB_HOST:-mysql}\n      - CONTAINER_ROLE=queue\n      - QUEUE_NAME=default     \n    depends_on:\n      - pgsql\n      - laravel\n    logging:\n      driver: \"json-file\"\n      options:\n        max-size: \"1m\"\n        max-file: \"5\"\n    restart: always\n```\nYou can launch as many queue container as you want. You have only to:\n\n* give an unique service name and unique container name\n* spcify the environment variables:\n  * CONTAINER_ROLE=quque to start the container as queue container\n  * QUEUE_NAME=\u003cqueue_name\u003e to specify the queue name\n\nThe final command launched inside the container is for example:\n\n```\nphp artisan queue:work database --queue=$QUEUE_NAME --verbose --tries=3\n```\n\nAn example of running laravel container as scheduler container is:\n\n```yaml\nscheduler:\n    image: garutilorenzo/laravel:php74-pgsql\n    build:\n      context: laravel/\n    container_name: scheduler\n    volumes:\n      - ${LARAVEL_DATA_DIR:-./laravel-project}:/var/www/html\n    environment:\n      - MYSQL_USER=${LARAVEL_DB_USER:-app}\n      - MYSQL_PASSWORD=${LARAVEL_DB_USER:-password}\n      - MYSQL_DATABASE=${LARAVEL_DB_NAME:-laravel}\n      - LARAVEL_DB_HOST=${LARAVEL_DB_HOST:-mysql}\n      - CONTAINER_ROLE=scheduler\n    depends_on:\n      - pgsql\n      - laravel\n    logging:\n      driver: \"json-file\"\n      options:\n        max-size: \"1m\"\n        max-file: \"5\"\n    restart: always\n```\n\nthe main part here is \"CONTAINER_ROLE=scheduler\", with this option the container starts an infinite loop an run the above command:\n\n```\nwhile [ true ]\ndo\n  php artisan schedule:run --verbose --no-interaction \u0026\n  sleep 60\ndone\n```\n\n### Enable SSL (optional)\n\nA configuration example is placed on config/nginx/conf.d/example.conf-ssl (rename the file with appropriate name, and delete/rename example.conf file)\nRemember to uncomment certbot service in docker-compose.yml-prod.\n\nIf you have to create a new SSL certificate using Let's Encrypt, modify init_letsencrypt.sh with your domain(s) name(s) and change the email variable.\nRequire the new certificate with:\n\n```console\nbash init_letsencrypt.sh\n```\nFor nginx auto reload, uncomment the *command* on the nginx service. This is necessary for auto reload nginx when certot renew the ssl certificates.\n\n\nIf you have your own SSL certificate modifiy config/nginx/conf.d/example.conf-ssl and docker-compose-yml-prod based on your needs (adjust the path to the certificates)\n\nYou can now start the services with:\n\n```console\ndocker-compose up -d\n```\n\n### Notes\n\n* MySQL sotre persistent data on mysql volume. The volume persist until command docker-compose down -v is gived.\n* Laravel docker image contains laravel v. 8.5.9. To persist your work download the laravel version you desire and extract the archive in laravel-project dir (at the same lavel on docker-compose.yml).\n* The name of the persistent directory of laravel (laravel-project) can be changed in .env file\n* To import existing database create sql/ directory at the same level of docker-compose.yml and uncomment \"./slq:/docker-entrypoint-initdb.d\" in the volume sections of the mysql service.\n* FORCE_MIGRATE environment variable (ose only on laravel service) whill force laravel to force migrations \"php artisan migrate --force\"\n* laravel container creates a .env enviroment file (laravel-project/.env) if no .env file exist. The file is created based on the enviroment varialbes attached to laravel service (MYSQL_USER, MYSQL_PASSWORD..). if .env file is found the file wont't be recreated/overwritten. If you provide an existing .env laravel file adjust to work wiht mysql container service.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarutilorenzo%2Flaravel-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarutilorenzo%2Flaravel-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarutilorenzo%2Flaravel-docker/lists"}