Caddy as reverse proxy for ephemeral branch based deployment with docker container

1. The problem I’m having:

I am setting up short lived preview deployment on single server for each merge request from gitlab CI. I was able to get everything working as follows:

  1. I run a new container for each branch
  2. from gitlab CI I generate a caddy config as follows: {
	reverse_proxy :41641

This works well until I have to restart the host machine.

When my host machine restarts, docker container runs on random port and the port specified in caddy config is no more the correct one and app goes down.

I need to figure out a way the port specified in caddy config can be corrected when docker container restarts.

Is there any plugin or preferred caddy way to achieve this?

2. Error messages and/or full log output:

No errror

3. Caddy version:


4. How I installed and ran Caddy:

a. System environment:

docker, ubuntu 22

b. My complete Caddy config: {
	reverse_proxy :41641

Please fill out the full template. The information requested in the template is necessary. We cannot help without it. Your issue appears like a Docker issue rather than a Caddy issue.

Thank you,
I have added details as per template…

This is related to how reverse proxy works in caddy,
I have read in internet that Traefik auto tracks change in port from name of docker container, so wanted to ask caddy community if there is better way to handle such change in port when host restarts.

You’re running Caddy with Docker, but your template details do not show any Docker config. Please share full details. I cannot help you with incomplete information. How are you running Caddy? How’s GitLab orchestrating the run? Where is the interaction between Docker and GitLab and Caddy?

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