Skip to content

Instantly share code, notes, and snippets.

@AlexR1712
Last active May 17, 2024 21:35
Show Gist options
  • Save AlexR1712/41fe68b1b9a645c74954e1a391b9607d to your computer and use it in GitHub Desktop.
Save AlexR1712/41fe68b1b9a645c74954e1a391b9607d to your computer and use it in GitHub Desktop.
Run Laravel Octane on docker using OpenSwoole and support to use Vite for Development
version: "3"
services:
php:
restart: unless-stopped
build:
context: .
target: development
dockerfile: Dockerfile
command: ["php", "artisan", "octane:start", "--server=swoole", "--host=0.0.0.0"]
ports:
- "8000:8000"
depends_on:
- mysql
environment:
- PHP_OPCACHE_ENABLE=1
- AUTORUN_ENABLED=false
- SSL_MODE=mixed
- DB_HOST=mysql
- DB_PORT=3306
- DB_DATABASE=homestead
- DB_USERNAME=homestead
- DB_PASSWORD=secret
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=password
volumes:
- .:/var/www/html
env_file:
- .env
mysql:
hostname: mysql
restart: unless-stopped
image: mysql:8.0.37-bookworm
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: 'homestead'
MYSQL_USER: 'homestead'
MYSQL_PASSWORD: 'secret'
MYSQL_ROOT_PASSWORD: 'secret'
volumes:
- database:/var/lib/mysql
node:
image: node:20
volumes:
- .:/var/www/html
working_dir: /var/www/html
vite:
image: node:20
volumes:
- .:/var/www/html
working_dir: /var/www/html
command: ["npm", "run", "dev"]
ports:
- "5173:5173"
## Container for test using image for Production
prod:
restart: unless-stopped
build:
context: .
target: production
dockerfile: Dockerfile
ports:
- "8001:8000"
depends_on:
- mysql
environment:
- PHP_OPCACHE_ENABLE=1
- AUTORUN_ENABLED=false
- SSL_MODE=mixed
- DB_HOST=mysql
- DB_PORT=3306
- DB_DATABASE=homestead
- DB_USERNAME=homestead
- DB_PASSWORD=secret
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=password
env_file:
- .env
volumes:
database:
# Frontend Image
FROM node:20 as frontend
RUN mkdir -p /app/public
COPY package.json package-lock.json vite.config.js /app/
# Copy your JavaScript source files
COPY resources/ /app/resources/
WORKDIR /app
# Install dependencies
RUN npm ci
# Run build
RUN npm build
# Base Image
FROM serversideup/php:8.3-cli AS base
# Switch to root so we can do root things
USER root
# Do root things
# Install the intl extension with root permissions
RUN install-php-extensions intl imagick bcmath gd json openswoole
# Drop back to our unprivileged user
USER www-data
# Development Image
FROM base AS development
# Install the xdebug extension with root permissions
# Switch to root so we can do it
USER root
RUN install-php-extensions xdebug
# Drop back to our unprivileged user
USER www-data
# Production Image
FROM base AS production
COPY --chown=www-data:www-data . /var/www/html
# Copy code JS/CSS build from frontend
COPY --from=frontend /app/public/build/ /var/www/html/public/build
CMD ["php", "artisan", "octane:start", "--server=swoole", "--host=0.0.0.0"]
HEALTHCHECK --interval=10m --timeout=5s \
CMD curl -f http://127.0.0.1:8000/up || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment