I’ve been testing a lot of images lately and this is a problem I’ve run into enough that I’m starting to think I’m doing something wrong. About 50% of the time when I’m testing an image, port forwarding works exactly as I expect it to, but the other 50% of the time I get the behavior described below. All my containers run behind a reverse proxy, each with its own subdomain. Currently I’m experiencing this problem with the Xwiki image. Here is my compose file:
version: '3.9'
networks:
my_net:
external: true
services:
xwiki_db:
image: postgres:16.2-alpine3.19
container_name: xwiki_db
volumes:
- ./db/:/var/lib/postgresql/data/
environment:
- POSTGRES_ROOT_PASSWORD=xwiki
- POSTGRES_PASSWORD=xwiki
- POSTGRES_USER=xwiki
- POSTGRES_DB=xwiki
- POSTGRES_INITDB_ARGS='--encoding=UTF8'
networks:
- my_net
xwiki:
image: xwiki:16.1.0-postgres-tomcat
container_name: xwiki
depends_on:
- xwiki_db
ports:
- '1234:8080'
environment:
- DB_USER=xwiki
- DB_PASSWORD=xwiki
- DB_HOST=xwiki_db
volumes:
- ./data/:/usr/local/xwiki/
networks:
- my_net
All my containers are on the Docker network my_net
, and it was created with this command:
sudo docker network create my_net
The Xwiki container has the IP address 172.17.0.6
My reverse proxy catches the request and forwards as expected, but it gets rejected by the Xwiki container with a 502 Bad Gateway error. Indeed, if I run the command sudo curl 172.17.0.6:1234
I get this error:
curl: (7) Failed to connect to 172.17.0.6 port 1234 after 0 ms: Connection refused
What is more curious is that I can run the command sudo curl 172.17.0.6:8080
and get no error. Further, I can change the reverse proxy configuration to use port 8080
instead of port 1234
, and without changing anything in the docker-compose.yml
config posted above be able to access Xwiki from a browser. This also makes no sense based on the output of sudo docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
110110abcdef xwiki:16.1.0-postgres-tomcat "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 0.0.0.0:1234->8080/tcp xwiki
In an attempt to simplify the environment and eliminate possible network conflicts, I deleted all my containers, networks, and the /var/lib/docker
directory, then recreated the my_net
network, the reverse proxy container, and the Xwiki container, but I got the same results.
What is going on here?