Docker-compose setup: how to reach other containers

Describe the issue/error/question

Is there anything specific to configure for n8n with docker-compose with the following goal(s):

  • docker-compose stack with n8n on-premise, in my case on Fedora 37 workstation
  • same host, another container running an API
  • both n8n and the api-container expose ports on the IPv4-IP of the host machine
  • in n8n I set up a http-request node that calls for example http://$myip:3011/someapi

with curl on the shell that call works, in n8n no result

Because the containers expose their ports to the host IP, I think it isn’t necessary to make them share the same docker network.

hints welcome!

Information on your n8n setup

  • n8n version: 0.214.1
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]: default, I assume
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Could you share your docker-compose? All services are sharing networks? Are you using localhost or service-name to make requests?

1 Like
# cat docker-compose.yml 
version: '3.8'

volumes:
  db_storage:
  n8n_storage:

services:
  postgres:
    image: postgres:11
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    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 ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    # image: n8nio/n8n
    # image: n8nio/n8n:0.205.0
    # image: n8nio/n8n:0.208.0
    #image: n8nio/n8n:0.212.1
    image: n8nio/n8n:0.214.1
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - N8N_BASIC_AUTH_ACTIVE=false
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - WEBHOOK_URL
      - N8N_EMAIL_MODE
      - N8N_SMTP_HOST
      - N8N_SMTP_PORT
      - N8N_SMTP_USER
      - N8N_SMTP_PASS
      - N8N_SMTP_SENDER
      - N8N_SMTP_SSL
    ports:
      - "192.168.97.161:5678:5678"
    links:
      - postgres
    volumes:
      - n8n_storage:/home/node/
        #command: /bin/sh -c "n8n start --tunnel"
    command: /bin/sh -c "n8n start"
    depends_on:
      postgres:
        condition: service_healthy

  my-converter:
    image: my-converter
    restart: always
    ports:
      - "3001:3001"

As you see above I now added the container to the same compose-stack as n8n.
I currently try “my-converter:3001” in the API call. Tested “localhost:3001” as well, same behavior, just takes a long time without a result.

I can telnet to port 3001 on IP and localhost.

Upgraded to n8n:0.214.2, btw.

Maybe my Dockerfile is wrong somehow? Not very likely, but you never know. I just googled some bits around dockering a nodejs app:

# Dockerfile, for a small nodejs app

FROM node:18-bullseye-slim
#FROM node:14.18.0-bullseye-slim

RUN apt-get update && apt-get install -y --no-install-recommends dumb-init
ENV NODE_ENV production
 
COPY package.json /tmp/package.json
#COPY package-lock.json /tmp/package-lock.json
 
RUN cd /tmp && npm install
#RUN npm ci --only=production

# Copy dependencies libraries
RUN mkdir /app && cp -a /tmp/node_modules /app/
 
COPY . /app

WORKDIR /app

# maybe not needed at all
RUN addgroup app && adduser node app
RUN mkdir node_modules/.cache
RUN chown node:app node_modules/.cache

USER node
 
EXPOSE 3001

CMD [ "dumb-init", "node", "index.js" ]

progress:

I started over from scratch. Removed docker images, rebuilt stuff etc

currently I successfully get results by calling

http://my-converter:3001/myAPIcall

So the name resolution inside the docker-compose stack is used and works.

Thanks for reading, sorry for the noise :wink:

1 Like

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