containers / containers/podman-compose
container to container communication in pod not working
- Dominant language
- Python
- Stars
- 6.2k
- Forks
- 622
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Communication via localhost is not possible when using rootless podman-compose but when manually creating the pod and the containers, then it is.
I'm having a `docker-compose.yml` file (contains postgresql and keycloak) and starting it via systemd (service files contains: `ExecStart=/home/MYUSER/.local/bin/podman-compose --in-pod=true --pod-args='-p 5432:5432 -p 8080:8080 -p 8443:8443 --network "slirp4netns:port_handler=slirp4netns"' up -d`).
postgresql starts and is ready:
```
postgresql 12:15:47.89 INFO ==> ** Starting PostgreSQL **
2023-08-29 10:15:48.022 GMT [1] LOG: pgaudit extension initialized
2023-08-29 10:15:48.045 GMT [1] LOG: starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-08-29 10:15:48.045 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-08-29 10:15:48.045 GMT [1] LOG: listening on IPv6 address "::", port 5432
2023-08-29 10:15:48.070 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2023-08-29 10:15:48.098 GMT [77] LOG: database system was shut down at 2023-08-29 10:13:40 GMT
2023-08-29 10:15:48.117 GMT [1] LOG: database system is ready to accept connections
```
keycloak is not able to reach postgresql via `localhost` or its docker-compose name `postgresql` or the generated container name `keycloak_postgresql_1` as `KEYCLOAK_DATABASE_HOST` value.
```
keycloak 10:15:49.16 INFO ==> ** Starting keycloak setup **
keycloak 10:15:49.17 INFO ==> Validating settings in KEYCLOAK_* env vars...
keycloak 10:15:49.18 INFO ==> Trying to connect to PostgreSQL server localhost...
timeout reached before the port went into state "inuse"
```
But if I manually create the pod, then run the postgresql and keycloak containers and assign them to the pod, keycloak can reach postgresql via localhost.
```
podman pod create \
--name keycloak_web \
-p 8080:8080 -p 8443:8443 \
--network 'slirp4netns:port_handler=slirp4netns'
podman run -d ...
```
**To Reproduce**
Steps to reproduce the behavior:
1. what is the content of the current working directory (ex. `docker-compose.yml`, `.env`, `Dockerfile`, ...etc.)
keycloak.service
```
[Unit]
Description=Podman-compose keycloak.service
Wants=network.target
After=network-online.target
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/srv/keycloak/keycloak
EnvironmentFile=/srv/keycloak/access.txt
ExecStartPre=/usr/bin/podman unshare chown 1001:1001 -R /srv/keycloak/ssl
ExecStart=/home/MYUSER/.local/bin/podman-compose --in-pod=true --pod-args='-p 5432:5432 -p 8080:8080 -p 8443:8443 --network "slirp4netns:port_handler=slirp4netns"' up -d
ExecStop=/home/MYUSER/.local/bin/podman-compose down
[Install]
WantedBy=default.target
```
docker-compose.yml
```
version: "3.9"
services:
postgresql:
image: "harbor1.my-domain.com/dh/bitnami/postgresql:15.2.0"
restart: always
environment:
POSTGRESQL_PASSWORD
volumes:
- /srv/postgresql/data-blue:/bitnami/postgresql:Z
- /etc/localtime:/etc/localtime:ro
shm_size: 256MB
keycloak:
image: "harbor1.my-domain.com/dh/bitnami/keycloak:21"
restart: always
depends_on:
- postgresql
environment:
KEYCLOAK_PRODUCTION: true
KEYCLOAK_CREATE_ADMIN_USER: true
KEYCLOAK_ADMIN_USER: keycloak-admin
KEYCLOAK_ADMIN_PASSWORD: $KEYCLOAK_ADMIN_PASSWORD
KEYCLOAK_MANAGEMENT_USER: wildfly-manager
KEYCLOAK_MANAGEMENT_PASSWORD: $KEYCLOAK_MANAGEMENT_PASSWORD
KEYCLOAK_DATABASE_VENDOR: postgresql
KEYCLOAK_DATABASE_HOST: localhost
KEYCLOAK_DATABASE_PORT: 5432
KEYCLOAK_DATABASE_NAME: bnkeycloak
KEYCLOAK_DATABASE_USER: bnkeycloak
KEYCLOAK_DATABASE_PASSWORD: $KEYCLOAK_DATABASE_PASSWORD
KEYCLOAK_ENABLE_HTTPS: true
KEYCLOAK_HTTPS_USE_PEM: true
KEYCLOAK_HTTPS_CERTIFICATE_FILE: /opt/bitnami/keycloak/certs/my-domain.com.fullchain.pem
KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE: /opt/bitnami/keycloak/certs/my-domain.com.key
volumes:
- /srv/keycloak/ssl:/opt/bitnami/keycloak/certs:z,ro
```
3. what is the sequence of commands you typed
```
systemctl --user daemon-reload
systemctl --user list-unit-files | grep keycloak
systemctl --user enable keycloak
systemctl --user start keycloak
```
**Expected behavior**
That it works via localhost the same way as when manually created the pod and the containers.
**Actual behavior**
Getting a timeout in keycloak container:
```
keycloak 10:15:49.18 INFO ==> Trying to connect to PostgreSQL server localhost...
timeout reached before the port went into state "inuse"
```
**Output**
$ podman-compose version
```
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.2.0
podman-compose version 1.0.6
podman --version
podman version 4.2.0
```
**Environment:**
- OS: Linux / WSL / Mac
```
NAME="Rocky Linux"
VERSION="9.1 (Blue Onyx)"
```
- podman version:
```
Client: Podman Engine
Version: 4.2.0
API Version: 4.2.0
Go Version: go1.18.9
Built: Tue Feb 28 17:34:15 2023
OS/Arch: linux/amd64
```
**Additional context**
I even compared the manually created pod and the pod created by podman-compose via `podman pod inspect ...` and both were nearly identical (except name in CreateCommand).
Contributor guide
Assessment
This issue has not been assessed yet.