Skip to main content
added 180 characters in body
Source Link
030
  • 13.3k
  • 16
  • 75
  • 175

I'm trying to connect from a node app container to a postgresql container using docker-compose but I'm not able to do it. This is my docker-compose.yml file: version: '3.7' services: db: image: postgres:12.1 ports: - "5432:5432" env_file: - "./.env" networks: - tcp-modbus volumes: - ./modbustcp.sql:/docker-entrypoint-initdb.d/init.sql redis: image: redis:5.0.6 ports: - "6379:6379" networks: - tcp-modbus rabbit: image: "rabbitmq" environment: RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG" RABBITMQ_DEFAULT_USER: "*" RABBITMQ_DEFAULT_PASS: "*" RABBITMQ_DEFAULT_VHOST: "/" ports: - "15672:15672" - "5672:5672" volumes: - "./enabled_plugins:/etc/rabbitmq/enabled_plugins" networks: - tcp-modbus modbus-tcp: image: customImage ports: - "8080:3000" links: - "db" volumes: - "./modbus.env:/usr/src/app/.env" networks: - tcp-modbus networks: tcp-modbus: driver: bridge

version: '3.7'
services:
  db:
    image: postgres:12.1
    ports:
      - "5432:5432"
    env_file:
      - "./.env"
    networks:
      - tcp-modbus
    volumes:
      - ./modbustcp.sql:/docker-entrypoint-initdb.d/init.sql
  redis:
    image: redis:5.0.6
    ports:
      - "6379:6379"
    networks:
      - tcp-modbus
  rabbit:
    image: "rabbitmq"
    environment:
      RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
      RABBITMQ_DEFAULT_USER: "*"
      RABBITMQ_DEFAULT_PASS: "*"
      RABBITMQ_DEFAULT_VHOST: "/"
    ports:
    - "15672:15672"
    - "5672:5672"
    volumes:
      - "./enabled_plugins:/etc/rabbitmq/enabled_plugins"
    networks:
      - tcp-modbus
  modbus-tcp:
    image: customImage
    ports:
      - "8080:3000"
    links:
      - "db"
    volumes:
      - "./modbus.env:/usr/src/app/.env"
    networks:
      - tcp-modbus
networks:
  tcp-modbus:
    driver: bridge

I'm trying to connect from a node app container to a postgresql container using docker-compose but I'm not able to do it. This is my docker-compose.yml file: version: '3.7' services: db: image: postgres:12.1 ports: - "5432:5432" env_file: - "./.env" networks: - tcp-modbus volumes: - ./modbustcp.sql:/docker-entrypoint-initdb.d/init.sql redis: image: redis:5.0.6 ports: - "6379:6379" networks: - tcp-modbus rabbit: image: "rabbitmq" environment: RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG" RABBITMQ_DEFAULT_USER: "*" RABBITMQ_DEFAULT_PASS: "*" RABBITMQ_DEFAULT_VHOST: "/" ports: - "15672:15672" - "5672:5672" volumes: - "./enabled_plugins:/etc/rabbitmq/enabled_plugins" networks: - tcp-modbus modbus-tcp: image: customImage ports: - "8080:3000" links: - "db" volumes: - "./modbus.env:/usr/src/app/.env" networks: - tcp-modbus networks: tcp-modbus: driver: bridge

I'm trying to connect from a node app container to a postgresql container using docker-compose but I'm not able to do it. This is my docker-compose.yml file:

version: '3.7'
services:
  db:
    image: postgres:12.1
    ports:
      - "5432:5432"
    env_file:
      - "./.env"
    networks:
      - tcp-modbus
    volumes:
      - ./modbustcp.sql:/docker-entrypoint-initdb.d/init.sql
  redis:
    image: redis:5.0.6
    ports:
      - "6379:6379"
    networks:
      - tcp-modbus
  rabbit:
    image: "rabbitmq"
    environment:
      RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
      RABBITMQ_DEFAULT_USER: "*"
      RABBITMQ_DEFAULT_PASS: "*"
      RABBITMQ_DEFAULT_VHOST: "/"
    ports:
    - "15672:15672"
    - "5672:5672"
    volumes:
      - "./enabled_plugins:/etc/rabbitmq/enabled_plugins"
    networks:
      - tcp-modbus
  modbus-tcp:
    image: customImage
    ports:
      - "8080:3000"
    links:
      - "db"
    volumes:
      - "./modbus.env:/usr/src/app/.env"
    networks:
      - tcp-modbus
networks:
  tcp-modbus:
    driver: bridge
Source Link

How to connect to postgres container from a node container using docker-compose?

I'm trying to connect from a node app container to a postgresql container using docker-compose but I'm not able to do it. This is my docker-compose.yml file: version: '3.7' services: db: image: postgres:12.1 ports: - "5432:5432" env_file: - "./.env" networks: - tcp-modbus volumes: - ./modbustcp.sql:/docker-entrypoint-initdb.d/init.sql redis: image: redis:5.0.6 ports: - "6379:6379" networks: - tcp-modbus rabbit: image: "rabbitmq" environment: RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG" RABBITMQ_DEFAULT_USER: "*" RABBITMQ_DEFAULT_PASS: "*" RABBITMQ_DEFAULT_VHOST: "/" ports: - "15672:15672" - "5672:5672" volumes: - "./enabled_plugins:/etc/rabbitmq/enabled_plugins" networks: - tcp-modbus modbus-tcp: image: customImage ports: - "8080:3000" links: - "db" volumes: - "./modbus.env:/usr/src/app/.env" networks: - tcp-modbus networks: tcp-modbus: driver: bridge

I'm using typeorm to set the connection from the node app and was working fine before dockerizing the app, maybe has something to do with the host name of the container, cause I'm using localhost to connect to the postgresql container. Can I use somehow the container network as a hostname to connect to postgres?