Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker for production #1834

Closed
wants to merge 12 commits into from
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM dunglas/frankenphp
arthurpar06 marked this conversation as resolved.
Show resolved Hide resolved

# Be sure to replace "demo.phpvms.net" by your domain name
ENV SERVER_NAME=demo.phpvms.net

# Enable PHP production settings
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN install-php-extensions \
pdo_mysql \
gd \
intl \
opcache \
curl \
mbstring \
json \
bcmath \
gmp \
zip \
redis

# Copy the PHP files of your project in the container
COPY . /app
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ make build-assets
```

This will build all of the assets according to the webpack file.

## Production Environment with Docker

You may also want to use Docker in production. We have chosen to use [FrankenPHP](https://frankenphp.dev/docs/), which is a module based on the [Caddy web server](https://caddyserver.com/docs/) and serves as a replacement for PHP-FPM. You will also have access to MariaDB and Redis.

First, you need to set your domain name in the `SERVER_NAME` of the `Dockerfile`

Then, to start the production environment, run:

```bash
docker-compose -f docker-compose.prod.yml up -d
```
68 changes: 68 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
services:
app:
build: .
restart: unless-stopped
ports:
- "${HTTP_PORT:-80}:80" # HTTP
- "${HTTPS_PORT:-443}:443" # HTTPS
- "${HTTPS_PORT:-443}:443/udp" # HTTP/3
volumes:
- caddy_data:/data
- caddy_config:/config
networks:
- internal
depends_on:
- mariadb
- redis

mariadb:
image: 'mariadb:11'
restart: unless-stopped
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
Comment on lines +41 to +42
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to expose ports if the DB will only be used for the app.

environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'no'
volumes:
- mariadb:/var/lib/mysql
networks:
- internal
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s

redis:
image: 'redis:alpine'
restart: unless-stopped
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
arthurpar06 marked this conversation as resolved.
Show resolved Hide resolved
volumes:
- redis:/data
networks:
- internal
healthcheck:
test:
- CMD
- redis-cli
- ping
retries: 3
timeout: 5s

# Volumes needed for Caddy certificates and configuration
volumes:
caddy_data:
caddy_config:
mariadb:
redis:

networks:
internal:
driver: bridge
Loading