Skip to content

Instantly share code, notes, and snippets.

@aguinaldotupy
Last active April 11, 2025 23:15
Show Gist options
  • Save aguinaldotupy/e7b88e01bfb5f536dcc08e71b2adde87 to your computer and use it in GitHub Desktop.
Save aguinaldotupy/e7b88e01bfb5f536dcc08e71b2adde87 to your computer and use it in GitHub Desktop.
Docker Laravel Octane / PHP 8.4 / Swoole
OCTANE_SERVER="swoole"
OCTANE_HTTPS="true"
WWWGROUP=1004
WWWUSER=1004
FROM ubuntu:24.04
LABEL maintainer="Aguinaldo Tupy"
ARG WWWGROUP=1004
ARG NODE_VERSION=22
ARG POSTGRES_VERSION=17
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=America/Sao_Paulo
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --host=0.0.0.0 --port='${APP_PORT:-80}'"
ENV SUPERVISOR_PHP_USER="deploy"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99custom && \
echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99custom && \
echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/99custom
RUN apt-get update && apt-get upgrade -y \
&& mkdir -p /etc/apt/keyrings \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python3 dnsutils librsvg2-bin fswatch ffmpeg vim openvpn iproute2 \
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.4-cli \
php8.4-pgsql php8.4-sqlite3 php8.4-gd \
php8.4-curl \
php8.4-imap php8.4-mysql php8.4-mbstring \
php8.4-xml php8.4-zip php8.4-bcmath php8.4-soap \
php8.4-intl php8.4-readline \
php8.4-ldap \
php8.4-msgpack php8.4-igbinary php8.4-redis \
php8.4-swoole php8.4-pcov php8.4-imagick \
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/keyrings/pgdg.gpg >/dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt noble-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y postgresql-client-$POSTGRES_VERSION \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.4
RUN userdel -r ubuntu
RUN groupadd --force -g $WWWGROUP deploy
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 deploy
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.4/cli/conf.d/99-production.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 80/tcp
ENTRYPOINT ["start-container"]
[PHP]
post_max_size = 2048M
upload_max_filesize = 2808M
variables_order = EGPCS
pcov.directory = .
services:
app:
build:
context: "./docker/production"
dockerfile: Dockerfile
args:
WWWGROUP: "${WWWGROUP:-1004}"
image: "my-app/app"
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "8081:80"
environment:
WWWUSER: "${WWWUSER:-1004}"
volumes:
- ".:/var/www/html"
networks:
- app-net
depends_on:
- database
- cache
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
database:
image: "postgis/postgis:17-3.5"
environment:
PGPASSWORD: "${DB_PASSWORD:-secret}"
POSTGRES_DB: "${DB_DATABASE}"
POSTGRES_USER: "${DB_USERNAME}"
POSTGRES_PASSWORD: "${DB_PASSWORD:-secret}"
volumes:
- "database-data:/var/lib/postgresql/data"
ports:
- "5433:5432"
networks:
- app-net
healthcheck:
test:
- CMD
- pg_isready
- "-q"
- "-d"
- "${DB_DATABASE}"
- "-U"
- "${DB_USERNAME}"
retries: 3
timeout: 5s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
cache:
image: "redis:alpine"
volumes:
- "cache-data:/data"
ports:
- "6381:6379"
networks:
- app-net
healthcheck:
test:
- CMD
- redis-cli
- ping
retries: 3
timeout: 5s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
networks:
app-net:
driver: bridge
volumes:
database-data:
driver: local
cache-data:
driver: local
#!/usr/bin/env bash
if [ ! -d /.composer ]; then
mkdir /.composer
fi
chmod -R ugo+rw /.composer
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:php]
command=%(ENV_SUPERVISOR_PHP_COMMAND)s
user=%(ENV_SUPERVISOR_PHP_USER)s
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment