Can I remove extraneous listening ports from docker container?

1. The problem I’m having:

I’m trying to use caddy in docker to serve a website and use reverse proxy for an API.

In our environment we also use Consul.

The problem I’m having is that the service is being registered against consul with the port suffix (my-frontend-80 instead of my-frontend. I believe this is because the docker container is listening on more than one port.

Is it possible to prevent the caddy container from listening on additional ports?

Example from docker inspect:

"Ports": {
     "2019/tcp": null,
     "443/tcp": null,
     "443/udp": null,
     "80/tcp": [
         {
             "HostIp": "0.0.0.0",
             "HostPort": "8080"
         }
     ]
},

This includes using the global caddy options:

{
	admin	off
	auto_https	off
}

2. Error messages and/or full log output:

3. Caddy version:

2.7.6

4. How I installed and ran Caddy:

a. System environment:

Docker

b. Command:

docker run --rm  --name my-frontend -p 8080:80 my-frontend:latest

c. Service/unit/compose file:

FROM caddy:2.7.6
WORKDIR /app
COPY ./caddy/Caddyfile /etc/caddy/Caddyfile
COPY ./dist/my-frontend/browser /usr/share/caddy

d. My complete Caddy config:

{
	admin off
	auto_https off
}

http://localhost:80 {
	encode gzip

	handle /api/* {
		uri strip_prefix /api
		reverse_proxy http://my-service.path.here:80
	}

	handle {
		root * /usr/share/caddy
		try_files {path} /index.html
		file_server
	}
}

5. Links to relevant resources:

I’ve never heard of that being a problem.

We define the ports here, in the Dockerfile: caddy-docker/2.7/alpine/Dockerfile at 5cc71afbebe1b590a9996c24e714e7b67ab53d03 · caddyserver/caddy-docker · GitHub

You could make your own Dockerfile without those things. You can grab the binary from the Caddy image with COPY --from caddy:2.7.6 /usr/bin/caddy /usr/bin/caddy I think.

Ah, thanks, yeah, that would explain it. I’ll give that a try and report back, hopefully later…

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