Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are some network issues with multi-container pods generated from compose #137

Open
nitezs opened this issue Jan 12, 2025 · 0 comments

Comments

@nitezs
Copy link

nitezs commented Jan 12, 2025

# compose.yaml
name: n8n
services:
  postgres:
    image: docker.io/library/postgres:16
    restart: unless-stopped
    environment:
      - POSTGRES_USER=changeUser
      - POSTGRES_PASSWORD=changePassword
      - POSTGRES_DB=n8n
      - POSTGRES_NON_ROOT_USER=changeUser
      - POSTGRES_NON_ROOT_PASSWORD=changePassword
    volumes:
      - ./db_storage:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h localhost -U changeUser -d n8n"]
      interval: 5s
      timeout: 5s
      retries: 10
    labels:
      - "io.containers.autoupdate=registry"
    networks:
      - n8n_network

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: unless-stopped
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=systemd-n8n-postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=changeUser
      - DB_POSTGRESDB_PASSWORD=changePassword
    ports:
      - 5678:5678
    volumes:
      - ./n8n_storage:/home/node/.n8n
    depends_on:
      - postgres
    labels:
      - "io.containers.autoupdate=registry"
    networks:
      - n8n_network

networks:
  n8n_network:
    driver: bridge

I generate quadlet files from this compose, and get

# n8n-postgres.container
[Container]
AutoUpdate=registry
Environment=POSTGRES_USER=changeUser POSTGRES_PASSWORD=changePassword POSTGRES_DB=n8n POSTGRES_NON_ROOT_USER=changeUser POSTGRES_NON_ROOT_PASSWORD=changePassword
HealthCmd=pg_isready -h localhost -U changeUser -d n8n
HealthInterval=5s
HealthRetries=10
HealthTimeout=5s
Image=docker.io/library/postgres:16
Network=n8n_network.network
Pod=n8n.pod
Volume=/home/nite/Downloads/pod/n8n/db_storage:/var/lib/postgresql/data
Volume=/home/nite/Downloads/pod/n8n/init-data.sh:/docker-entrypoint-initdb.d/init-data.sh

[Service]
Restart=always

[Install]
WantedBy=default.target

---

# n8n-n8n.container
[Unit]
Requires=n8n-postgres.service
After=n8n-postgres.service

[Container]
AutoUpdate=registry
Environment=DB_TYPE=postgresdb DB_POSTGRESDB_HOST=systemd-n8n-postgres DB_POSTGRESDB_PORT=5432 DB_POSTGRESDB_DATABASE=n8n DB_POSTGRESDB_USER=changeUser DB_POSTGRESDB_PASSWORD=changePassword
Image=docker.n8n.io/n8nio/n8n
Network=n8n_network.network
Pod=n8n.pod
Volume=/home/nite/Downloads/pod/n8n/n8n_storage:/home/node/.n8n

[Service]
Restart=always

[Install]
WantedBy=default.target

---

# n8n_network.network
[Network]
Driver=bridge

[Install]
WantedBy=default.target

---

# n8n.pod
[Pod]
PublishPort=5678:5678

[Install]
WantedBy=default.target

I found that I could not access n8n from the host through 5678. At this time, the host port listening status was

❯ lsof -i :5678
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
passt.avx 712691 nite 6u IPv6 2928872 0t0 TCP *:rrac (LISTEN)

When I removed PublishPort=5678:5678 from the .pod file and added it to n8n-n8n.container, the problem was solved.

# n8n-n8n.container
[Unit]
Requires=n8n-postgres.service
After=n8n-postgres.service

[Container]
AutoUpdate=registry
Environment=DB_TYPE=postgresdb DB_POSTGRESDB_HOST=systemd-n8n-postgres DB_POSTGRESDB_PORT=5432 DB_POSTGRESDB_DATABASE=n8n DB_POSTGRESDB_USER=changeUser DB_POSTGRESDB_PASSWORD=changePassword
Image=docker.n8n.io/n8nio/n8n
Network=n8n_network.network
Pod=n8n.pod
Volume=/home/nite/Downloads/pod/n8n/n8n_storage:/home/node/.n8n
PublishPort=5678:5678

[Service]
Restart=always

[Install]
WantedBy=default.target

---
#n8n.pod
[Pod]

[Install]
WantedBy=default.target

At this time, the host port listening status is

❯ lsof -i:5678
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rootlessp 740334 nite 10u IPv6 3040438 0t0 TCP \*:rrac (LISTEN)

Is this as expected or a bug?

In addition, I found that a container in a compose file connect to another container not using the name of the container in the compose file. For example, in this compose file, the n8n container connect to the postgres container through systemd-n8n-postgres. If using postgres, a dns error will be obtained. This is a bit confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant