Guten Tag,
ich bin gerade dabei, Shopware 6 auf mit Docker einzurichten mit Caddy, MySQL 8.0 und PHP 8.2 FPM.
Hier sind die jeweiligen Dockerfile
docker-compose.yml
version: '3.9'
networks:
caddy:
external: true
internal: {}
services:
php-lcmp-sw2:
build: ./php_docker/
volumes:
- './www/:/var/www/html/'
networks:
- internal
- caddy
caddy-lcmp-sw2:
build: ./caddy_docker/
depends_on:
- php-lcmp-sw2
restart: unless-stopped
volumes:
- './www/:/var/www/html/'
- './caddy_docker/Caddyfile:/etc/caddy/Caddyfile'
- 'caddy_data:/data'
- 'caddy_config:/config'
labels:
caddy: sw2.vanill.at
caddy.reverse_proxy: '{{upstreams}}'
networks:
- internal
- caddy
mysql-lcmp-sw2:
image: 'mysql:8.0'
environment:
MYSQL_ROOT_PASSWORD: <redacted>
volumes:
- 'mysqldata:/var/lib/mysql'
networks:
- internal
phpmyadmin-lcmp-sw2:
image: 'phpmyadmin/phpmyadmin:latest'
ports:
- '8091:80'
environment:
PMA_HOST: mysql-lcmp-sw2
networks:
- internal
depends_on:
- mysql-lcmp-sw2
volumes:
mysqldata: {}
caddy_data: {}
caddy_config: {}
/caddy_docker/Caddyfile
:80 {
route {
@default {
not path /theme/* /media/* /thumbnail/* /bundles/* /sitemap/*
}
encode gzip zstd
root * /var/www/html/public/
php_fastcgi php-lcmp-sw2:9000 {
trusted_proxies private_ranges
}
file_server
header {
-server
-Link
-X-Powered-By
# disable FLoC tracking
#Permissions-Policy interest-cohort=()
# enable HSTS
Strict-Transport-Security max-age=31536000;
# disable clients from sniffing the media type
X-Content-Type-Options nosniff
# clickjacking protection
X-Frame-Options DENY
# keep referrer data off of HTTP connections
Referrer-Policy no-referrer-when-downgrade
}
}
log
}
/caddy_docker/Dockerfile
# Use the official Caddy Docker image
FROM caddy:latest
# Update package index and upgrade installed packages
RUN apk update && apk upgrade
# Copy Caddyfile to configure Caddy server
COPY Caddyfile /etc/caddy/Caddyfile
/php_docker/Dockerfile
FROM php:8.2-fpm-alpine
# Downloading install-php-extensions script and making it executable
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
# Making install-php-extensions script executable
RUN chmod +x /usr/local/bin/install-php-extensions
# Installing PHP extensions using install-php-extensions script
RUN install-php-extensions \
mysqli \
pdo \
pdo_mysql \
gd \
zip \
intl \
xml \
curl \
dom \
fileinfo \
iconv \
json \
libxml \
mbstring \
openssl \
pcre \
phar \
simplexml \
zlib \
soap
# Setting PHP directives
RUN echo 'memory_limit = 512M' > /usr/local/etc/php/conf.d/memory-limit.ini
RUN echo 'max_execution_time = 300' > /usr/local/etc/php/conf.d/max-execution-time.ini
RUN echo 'max_input_vars = 10000' > /usr/local/etc/php/conf.d/max-input-vars.ini
RUN echo 'max_input_time = 300' > /usr/local/etc/php/conf.d/max-input-time.ini
RUN echo 'opcache.revalidate_freq=0' > /usr/local/etc/php/conf.d/opcache-revalidate-freq.ini
RUN echo 'opcache.validate_timestamps=0' > /usr/local/etc/php/conf.d/opcache-validate-timestamps.ini
RUN echo 'opcache.max_accelerated_files=7963' > /usr/local/etc/php/conf.d/opcache-max-accelerated-files.ini
RUN echo 'opcache.memory_consumption=256' > /usr/local/etc/php/conf.d/opcache-memory-consumption.ini
RUN echo 'opcache.interned_strings_buffer=16' > /usr/local/etc/php/conf.d/opcache-interned-strings-buffer.ini
RUN echo 'opcache.fast_shutdown=1' > /usr/local/etc/php/conf.d/opcache-fast-shutdown.ini
RUN echo 'display_errors=1' > /usr/local/etc/php/conf.d/display-errors.ini
RUN echo 'error_reporting=-1' > /usr/local/etc/php/conf.d/error-reporting.ini
# Cleaning up
RUN rm -rf /var/cache/apk/*
Ist Caddy überhaupt der richtige Server für Shopware 6, ich habe hier zwei unterschiedlichen Angaben bezüglich der Voraussetzungen gefunden
Apache 2.4 oder ngnix
Caddy
Ich konnte Shopware 6 auf dem Docker setup fehlerfrei zum laufen bringen, habe dann allerdings einen reverse proxy davor geschaltet und seither habe ich einen mixed content Fehler. In der .env ist bereits ein TRUSTED PROXY hinterlegt siehe
/www/public/.env
###> shopware/core ###
APP_ENV=prod
APP_URL=http://127.0.0.1:8000
APP_SECRET=0f64204923a7a2bf661a3d0e8de01b4b
INSTANCE_ID=8e569cc97c947b396badf59c64232c3f
BLUE_GREEN_DEPLOYMENT=0
DATABASE_URL=mysql://root:root@localhost/shopware
# With Shopware 6.4.17.0 the MAILER_DSN variable will be used in this template instead of MAILER_URL
MAILER_URL=null://null
###< shopware/core ###
###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
# doctrine://default?auto_setup=0
###< symfony/messenger ###
###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###
###> symfony/lock ###
# Choose one of the stores below
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=flock
###< symfony/lock ###
TRUSTED_PROXIES=192.168.192.0/20
TRUSTED_PROXIES=0.0.0.0/0
TRUSTED_HEADERS='["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-forwarded-port", "x-forwarded-prefix"]'
###> shopware/elasticsearch ###
OPENSEARCH_URL=http://localhost:9200
SHOPWARE_ES_ENABLED=0
SHOPWARE_ES_INDEXING_ENABLED=0
SHOPWARE_ES_INDEX_PREFIX=sw
SHOPWARE_ES_THROW_EXCEPTION=1
###< shopware/elasticsearch ###
###> shopware/storefront ###
STOREFRONT_PROXY_URL=http://localhost
SHOPWARE_HTTP_CACHE_ENABLED=1
SHOPWARE_HTTP_DEFAULT_TTL=7200
###< shopware/storefront ###
In der framework.yaml im Ordner /config/packages (die Datei musste ich neu erstellen, diese gab es per default nicht) habe ich laut dieser Anleitung folgendes gesetzt
https://symfony.com/doc/current/deployment/proxies.html
# config/packages/framework.yaml
framework:
# ...
# the IP address (or range) of your proxy
trusted_proxies: '192.168.192.1,0.0.0.0/0'
# trust *all* "X-Forwarded-*" headers
trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix']
# or, if your proxy instead uses the "Forwarded" header
# trusted_headers: ['forwarded']
Hier noch Infos zur Docker-Umgebung
docker network inspect caddy
[
{
"Name": "caddy",
"Id": "65114c19b964e74adaeb71e7259dec415d57f2fd07ee5b6ffa505ddd298e7170",
"Created": "2024-04-07T21:56:41.90359249+02:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.192.0/20",
"Gateway": "192.168.192.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
930f060e56cc lcmpsw2-caddy-lcmp-sw2 "caddy run --config …" 17 minutes ago Up 17 minutes 80/tcp, 443/tcp, 2019/tcp, 443/udp lcmpsw2-caddy-lcmp-sw2-1
5d0e296edcea phpmyadmin/phpmyadmin:latest "/docker-entrypoint.…" 17 minutes ago Up 17 minutes 0.0.0.0:8091->80/tcp, :::8091->80/tcp lcmpsw2-phpmyadmin-lcmp-sw2-1
2e9845d5b22b lcmpsw2-php-lcmp-sw2 "docker-php-entrypoi…" 17 minutes ago Up 17 minutes 9000/tcp lcmpsw2-php-lcmp-sw2-1
9f1f0f1b97b8 mysql:8.0 "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 3306/tcp, 33060/tcp lcmpsw2-mysql-lcmp-sw2-1
d9b989e58892 lucaslorentz/caddy-docker-proxy:ci-alpine "/bin/caddy docker-p…" 20 hours ago Up 20 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:443->443/udp, :::443->443/udp, 2019/tcp srv-caddy-1
Interessant ist, dass das Setup ohne dem reverse proxy fehlerfrei funktioniert. Ich muss es aber mit einem reverse proxy betreiben, da auch andere Dienste / Docker container auf dem Server laufen, die sich sonst gegenseitig die Ports blockieren würden.
ich bin unendlich dankbar für Hinweise, da ich jetzt schon Wochen nach dem Fehler suche und einfach nicht weiter komme!
Schönen Tag und beste Grüße!