How to expose Caddy Server to another Port ?

Hello, I have a project in Dockerize Symfony (php) app and I would like to expose on port 5000. I have tried using certain command in the doc but I have errors displayed.

The goal is to integrate it into a gitlab autodevops project which automatically detects docker images but the constraint and that the web server must be exposed on port 5000 for everything to work

Caddyfile :


{
    experimental_http3
}
localhost{
tls example@example.com
}
:5000
log

route {
    root * /srv/app/public
    vulcain
    push
    php_fastcgi php:9000
    encode gzip
    file_server
}

Dockerfile


ARG PHP_VERSION=8.0
ARG CADDY_VERSION=2

// "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php

//persistent / runtime deps
RUN apk add --no-cache \
        acl \
        fcgi \
        file \
        gettext \
        git \
        jq \
    ;

ARG APCU_VERSION=5.1.19
RUN set -eux; \
	apk add --no-cache --virtual .build-deps \
	    $PHPIZE_DEPS \
	    icu-dev \
	    libzip-dev \
	    zlib-dev \
	; \
	\
	docker-php-ext-configure zip; \
	docker-php-ext-install -j$(nproc) \
	    intl \
	    zip \
	; \
	pecl install \
	    apcu-${APCU_VERSION} \
	; \
	pecl clear-cache; \
	docker-php-ext-enable \
	    apcu \
	    opcache \
	; \
	\
	runDeps="$( \
	    scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
	        | tr ',' '\n' \
	        | sort -u \
	        | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
	)"; \
	apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
	\
	apk del .build-deps

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/symfony.prod.ini $PHP_INI_DIR/conf.d/symfony.ini

RUN set -eux; \
	{ \
		echo '[www]'; \
		echo 'ping.path = /ping'; \
	} | tee /usr/local/etc/php-fpm.d/docker-healthcheck.conf

//https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1

ENV PATH="${PATH}:/root/.composer/vendor/bin"

WORKDIR /srv/app

// Allow to use development versions of Symfony
ARG STABILITY="stable"
ENV STABILITY ${STABILITY:-stable}

//Allow to select skeleton version
ARG SYMFONY_VERSION=""

// Download the Symfony skeleton and leverage Docker cache layers
RUN composer create-project "symfony/skeleton ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-interaction; \
	composer clear-cache

COPY . .

RUN set -eux; \
	mkdir -p var/cache var/log; \
	composer install --prefer-dist --no-dev --no-progress --no-scripts --no-interaction; \
	composer dump-autoload --classmap-authoritative --no-dev; \
	composer symfony:dump-env prod; \
	composer run-script --no-dev post-install-cmd; sync
VOLUME /srv/app/var

COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder

RUN xcaddy build \
    --with github.com/dunglas/mercure@main \
    --with github.com/dunglas/mercure/caddy@main \
    --with github.com/dunglas/vulcain/caddy

FROM caddy:${CADDY_VERSION} AS symfony_caddy

WORKDIR /srv/app

ENV MERCURE_DEMO="demo /srv/mercure-assets/"
COPY --from=dunglas/mercure:v0.11 /srv/public /srv/mercure-assets/
COPY --from=symfony_caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --from=symfony_php /srv/app/public public/
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile

Please fill out the template. Unfortunately, there is not enough information here for us to help you. :frowning:

You seem to have a few syntax issues with your Caddyfile.

First, you must have a space before the { after localhost

Next, you must use braces around your second site (i.e. next to :5000 add a { then at the end add a }).

Then I recommend you run the caddy fmt command to clean up the indentation automatically.

Also, it won’t be possible to have a single container with both PHP and Caddy, because Docker containers only run a single process. Caddy does not run PHP, it only connects to a fastcgi server (i.e. php-fpm). So you should separate that Dockerfile in two.

/cc @dunglas

This topic was automatically closed after 30 days. New replies are no longer allowed.