0

I have a postgres container running as host network_mode and a Nextcloud container running on default (bridged) network with port 8080:80.

How can I link the containers so that Nextcloud can access postgres? I've tried adding this to my docker-compose.yml, but it doesn't seem to work.

services:
    nextcloud:
        external_links:
         - "postgres:postgres"

Command I use to run postgres:

docker run --name postgres --net host --restart always postgres

When I do that, it gives me this error

Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[08006] [7] could not translate host name "postgres" to address: Name or service not known

Alternate Option: How can I define the port I want nextcloud to listen on, so I can use it on the host network?

cclloyd
  • 583
  • 1
  • 13
  • 24

1 Answers1

0

It is not recommended to run containers with --net host. You can just include postgres in you docker-compose without much effort:

services:
  postgres:
    image: postgres
    restart: always
    volumes:
      - db:/var/lib/postgresql/data
  app:
    image: nextcloud
    ports:
      - 8080:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
    restart: always

A network will be created automatically, so that you can now connect to the database on postgres.

Alwinius
  • 150
  • 4