2 years ago
There are many ways you can add Docker to your Laravel application, but how do you add docker to your Laravel application when you need sub domain support? Create a docker-compose.yaml in the root of your Laravel application. Let’s walk through the compose file now: Our Nginx Service nginx: container_name: "${PROJECT_NAME}_nginx" build: context:./docker/nginx dockerfile: Dockerfile depends_on: - app volumes: -./:/var/www/vhost/crm:cached -./docker/nginx/nginx.conf:/etc/nginx/nginx.conf -./docker/nginx/conf.d:/etc/nginx/conf.d -./docker/nginx/ssl:/etc/nginx/ssl working_dir: /var/www/vhost/ ports: - '443:443' - '9008:9008' networks: - crm labels: - 'traefik.http.routers.${PROJECT_NAME}_nginx.rule=HostRegexp(`${APP_DOMAIN}`, `{subdomain:[a-z]+.${APP_DOMAIN}}`)' - 'traefik.http.routers.${PROJECT_NAME}_nginx.priority=1' - 'traefik.docker.network=proxy' The nginx Dockerfile should be created under: docker/nginx/Dockerfile and contain the following: # Offical Docker Image for Nginx # https://hub.docker.com/_/nginx FROM nginx:alpine install: @composer install test: @docker exec $(PROJECT_NAME)_php./vendor/bin/pest --parallel coverage: @docker exec $(PROJECT_NAME)_php./vendor/bin/pest --coverage migrate: @docker exec $(PROJECT_NAME)_php php artisan migrate seed: @docker exec $(PROJECT_NAME)_php php artisan db:seed fresh: @docker exec crm_php php artisan migrate:fresh analyse: ./vendor/bin/phpstan analyse --memory-limit=256m generate: @docker exec $(PROJECT_NAME)_php php artisan ide-helper:models --write nginx: @docker exec -it $(PROJECT_NAME)_nginx /bin/sh php: @docker exec -it $(PROJECT_NAME)_php /bin/sh mysql: @docker exec -it $(PROJECT_NAME)_mysql /bin/sh redis: @docker exec -it $(PROJECT_NAME)_redis /bin/sh