Skip to content

Instantly share code, notes, and snippets.

@m-triassi
Last active November 14, 2024 06:07
Show Gist options
  • Save m-triassi/7398dcd31caf6de97ebb95a878abd4b5 to your computer and use it in GitHub Desktop.
Save m-triassi/7398dcd31caf6de97ebb95a878abd4b5 to your computer and use it in GitHub Desktop.
Production Ready Docker for Laravel
See the blog post here: https://blog.triassi.ca/blog/01-docker-laravel-production/
# in project directory ./entrypoint.d/
php artisan migrate --force
php artisan storage:link
php artisan optimize
{
email [email protected]
}
example.com {
reverse_proxy app:8080
}
services:
app:
image: ghcr.io/USER/IMAGE
container_name: app
volumes:
- .env:/var/www/html/.env
ports:
- "8080:8080"
- "8443:8443"
networks:
- web-public
depends_on:
mysql:
condition: service_healthy
mysql:
image: mysql
restart: "unless-stopped"
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
ports:
- "${DB_PORT}:3306"
networks:
- web-public
volumes:
- mysql-db:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
caddy:
image: caddy:latest
restart: unless-stopped
container_name: caddy
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
networks:
- web-public
depends_on:
- app
watchtower:
image: containrrr/watchtower
environment:
- TZ=America/New_York
- WATCHTOWER_POLL_INTERVAL=3600
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
networks:
web-public:
driver: bridge
external: true
volumes:
mysql-db:
caddy_data:
external: true
caddy_config:
# Adjust NODE_VERSION as desired
ARG NODE_VERSION=23.1.0
FROM node:${NODE_VERSION}-slim as build
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3
# Install node modules
COPY package-lock.json package.json ./
RUN npm ci --include=dev
# Copy application code
COPY . .
# Build application
RUN npm run build
# Remove development dependencies
RUN npm prune --omit=dev
FROM serversideup/php:8.3-fpm-nginx-bookworm
# Load custom entrypoint scripts
COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/
# Copy our app files as www-data (33:33)
COPY --chown=www-data:www-data --from=build /app /var/www/html
# Install composer dependencies for production
RUN composer install --no-dev --no-interaction --no-progress --optimize-autoloader --prefer-dist --classmap-authoritative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment