# Can't connect to Postgres DB inside another docker container

**URL:** <https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725>\
**Category:** Help me!\
**Created:** [July 25, 2020, 10:59am UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725 "2020-07-25T10:59:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 25, 2020, 10:59am UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/1 "2020-07-25T10:59:46Z")

</div>

I’m trying to install the community edition using docker but my DB is running inside a different docker container and I’m using a custom port. I can access it without any problems via `psql` but I get an error when I run this command:

```javascript
sudo docker run \
> -v `pwd`:/usr/src/app --init \
> -e DATABASE_SCHEMA="public" \
> -e DATABASE_SSL="false" \
> -e DATABASE_URL="postgres://user:password@host.docker.internal:5555/my_database" \
> -e APP_NAME="REDACTED" \
> -e FOREST_EMAIL="REDACTED" \
> -e FOREST_TOKEN="REDACTED" \
> -e APPLICATION_HOST="localhost" \
> -e APPLICATION_PORT="3310" \
> -ti forestadmin/lumber
✖ Connecting to your database
> Cannot connect to the database due to the following error:
> SequelizeHostNotFoundError: getaddrinfo ENOTFOUND host.docker.internal host.docker.internal:5555

```

If I change `host.docker.internal` to `localhost` I get this error:

```javascript
✖ Connecting to your database
> Cannot connect to the database due to the following error:
> SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5555

```

I’m using Docker 18.09 and Postgres 12

---

<div class="post-metadata">

**Author:** ![anon37102731](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@anon37102731](https://community.forestadmin.com/u/anon37102731)\
**Post date:** [July 27, 2020, 8:32am UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/2 "2020-07-27T08:32:58Z")

</div>

Hi @nacho,

Welcome to the ForestAdmin community and thank you for reaching out with your issue.

In order to help you, could you please tell me on which OS you’re trying to run this command?

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 27, 2020, 10:38am UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/3 "2020-07-27T10:38:33Z")

</div>

Thanks, Valentin.

My VPS is using Ubuntu 18.04, but the docker image with the Postgres DB has Debian 10.

---

<div class="post-metadata">

**Author:** ![anon37102731](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@anon37102731](https://community.forestadmin.com/u/anon37102731)\
**Post date:** [July 27, 2020, 1:17pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/4 "2020-07-27T13:17:17Z")

</div>

@nacho, the `docker run` you shared looks like one generated either on a mac or windows OS.

I’m assuming that you made your onboarding on a windows or mac OS and then copy paste it to a Linux OS ?

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 27, 2020, 1:28pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/5 "2020-07-27T13:28:41Z")

</div>

That’s correct. I didn’t log on to the website from my Linux VPS. I did it from my Mac. What should I change?

---

<div class="post-metadata">

**Author:** ![anon37102731](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@anon37102731](https://community.forestadmin.com/u/anon37102731)\
**Post date:** [July 27, 2020, 1:53pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/6 "2020-07-27T13:53:27Z")

</div>

If you’re able to, yes, it is the simplest way.

But if you cannot, I’ll highlight what to change from the generated CLI command to make it work.

Just let me know 🙂

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 27, 2020, 2:04pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/7 "2020-07-27T14:04:52Z")

</div>

> [@anon37102731](#):
>
> I’ll highlight what to change from the generated CLI command to make it work

Yes, please. I wouldn’t know how to connect to the website from the command line

---

<div class="post-metadata">

**Author:** ![anon37102731](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@anon37102731](https://community.forestadmin.com/u/anon37102731)\
**Post date:** [July 27, 2020, 2:14pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/8 "2020-07-27T14:14:13Z")

</div>

Sure,

Having the CLI command given by the UI on macOS, you need to:

- Add a `--network host` just after the `--init`
- replace all occurrences of `host.docker.internal` by `localhost`

Let me know if it works correctly for you.

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 27, 2020, 2:34pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/9 "2020-07-27T14:34:19Z")

</div>

Thanks. It’s a step forward, but now I get this:

```javascript
✓ Connecting to your database
✖ Analyzing the database
> Cannot generate your project.
> An unexpected error occurred. Please reach out for help in our Slack community or create a Github issue with following error: SequelizeDatabaseError: more than one row returned by a subquery used as an expression
(node:15) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: more than one row returned by a subquery used as an expression
    at Query.formatError (/usr/local/lib/node_modules/lumber-cli/node_modules/sequelize/lib/dialects/postgres/query.js:366:16)
    at query.catch.err (/usr/local/lib/node_modules/lumber-cli/node_modules/sequelize/lib/dialects/postgres/query.js:72:18)
    at tryCatcher (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/lumber-cli/node_modules/bluebird/js/release/async.js:15:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
(node:15) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

```

---

<div class="post-metadata">

**Author:** ![anon37102731](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@anon37102731](https://community.forestadmin.com/u/anon37102731)\
**Post date:** [July 27, 2020, 3:02pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/10 "2020-07-27T15:02:22Z")

</div>

@nacho could you please share with me the lumber version you’re using to generate your project?

`lumber --version` should do the job.

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 27, 2020, 4:01pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/11 "2020-07-27T16:01:49Z")

</div>

Hi, Valentin. I don’t have `lumber` installed. All I did was execute the `docker run` command. Should I install it?

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [July 29, 2020, 6:59am UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/12 "2020-07-29T06:59:19Z")

</div>

Hi @nacho,

Could you try to generate your project with lumber instead of docker. If it still do not works add `DEBUG=*` before the `lumber generate` command.

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 29, 2020, 8:02am UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/13 "2020-07-29T08:02:05Z")

</div>

Thanks, Vince. I was able to get the problematic SQL command using the log. It appears that the problem is that the Comment subquery returns multiple (duplicated) rows. Is there anything I can do to fix it

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/25951c5cf3cfe4b1203599408c7e36796c5883fb.png)

Here is the full query:

```javascript
sequelize:sql:pg Executing (default): SELECT pk.constraint_type as "Constraint",c.column_name as "Field", c.column_default as "Default",c.is_nullable as "Null", (CASE WHEN c.udt_name = 'hstore' THEN c.udt_name ELSE c.data_type END) || (CASE WHEN c.character_maximum_length IS NOT NULL THEN '(' || c.character_maximum_length || ')' ELSE '' END) as "Type", (SELECT array_agg(e.enumlabel) FROM pg_catalog.pg_type t JOIN pg_catalog.pg_enum e ON t.oid=e.enumtypid WHERE t.typname=c.udt_name) AS "special", (SELECT pgd.description FROM pg_catalog.pg_statio_all_tables AS st INNER JOIN pg_catalog.pg_description pgd on (pgd.objoid=st.relid) WHERE c.ordinal_position=pgd.objsubid AND c.table_name=st.relname) AS "Comment" FROM information_schema.columns c LEFT JOIN (SELECT tc.table_schema, tc.table_name, cu.column_name, tc.constraint_type FROM information_schema.TABLE_CONSTRAINTS tc JOIN information_schema.KEY_COLUMN_USAGE cu ON tc.table_schema=cu.table_schema and tc.table_name=cu.table_name and tc.constraint_name=cu.constraint_name and tc.constraint_type='PRIMARY KEY') pk ON pk.table_schema=c.table_schema AND pk.table_name=c.table_name AND pk.column_name=c.column_name WHERE c.table_name = 'posts' AND c.table_schema = 'public' +2ms
  sequelize:pool connection released +17ms
✖ Analyzing the database
> Cannot generate your project.
> An unexpected error occurred. Please reach out for help in our Slack community or create a Github issue with following error: SequelizeDatabaseError: more than one row returned by a subquery used as an expression
  superagent POST https://forestadmin-server.herokuapp.com/api/lumber/error +0ms
(node:20158) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: more than one row returned by a subquery used as an expression

```

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [July 29, 2020, 12:59pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/14 "2020-07-29T12:59:38Z")

</div>

This query is something automatically generated by Sequelize. But I can’t find any issues related to that. Could you please share a full record result with all columns of that subquery comment so I can investigate what is going on ? I don’t have the issue on my side.

Out of curiosity, do you have multiple schemas with the same tables ?

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 29, 2020, 1:38pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/15 "2020-07-29T13:38:34Z")

</div>

> [@anon62739609](#):
>
> Out of curiosity, do you have multiple schemas with the same tables ?

That seems to see the problem. I have a `backup` schema and if I simply add `AND st.schemaname = 'public'` I don’t get the error. Here it is in context (line 29, I’ve added a comment):

```javascript
SELECT
  pk.constraint_type AS "Constraint",
  c.column_name AS "Field",
  c.column_default AS "Default",
  c.is_nullable AS "Null",
  (
    CASE WHEN c.udt_name = 'hstore' THEN c.udt_name ELSE c.data_type END
  ) || (
    CASE WHEN c.character_maximum_length IS NOT NULL THEN '(' || c.character_maximum_length || ')' ELSE '' END
  ) AS "Type",
  (
    SELECT
      array_agg(e.enumlabel)
    FROM
      pg_catalog.pg_type t
      JOIN pg_catalog.pg_enum e ON t.oid = e.enumtypid
    WHERE
      t.typname = c.udt_name
  ) AS "special",
  (
    SELECT
      pgd.description
    FROM
      pg_catalog.pg_statio_all_tables AS st
      INNER JOIN pg_catalog.pg_description pgd ON (pgd.objoid = st.relid)
    WHERE
      c.ordinal_position = pgd.objsubid
      AND c.table_name = st.relname
      AND st.schemaname = 'public' -- <== I ADDED THIS
  ) AS "Comment"
FROM
  information_schema.columns c
  LEFT JOIN (
    SELECT
      tc.table_schema,
      tc.table_name,
      cu.column_name,
      tc.constraint_type
    FROM
      information_schema.TABLE_CONSTRAINTS tc
      JOIN information_schema.KEY_COLUMN_USAGE cu ON tc.table_schema = cu.table_schema
      AND tc.table_name = cu.table_name
      AND tc.constraint_name = cu.constraint_name
      AND tc.constraint_type = 'PRIMARY KEY'
  ) pk ON pk.table_schema = c.table_schema
  AND pk.table_name = c.table_name
  AND pk.column_name = c.column_name
WHERE
  c.table_name = 'posts'
  AND c.table_schema = 'public'

```

I’m specifying the schema name (`public`) when I answer the lumber questions but it seems this is not being taken into account for the subquery.

How can I add this piece of code so I can generate the app with the lumber command?

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [July 29, 2020, 3:09pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/16 "2020-07-29T15:09:46Z")

</div>

It’s in Sequelize in this [file](https://github.com/sequelize/sequelize/blob/042cd693635ffba83ff7a2079974692af6f710a7/src/dialects/postgres/query-generator.js#L136). I’ll need to do a Pull Request or if you want to do one feel free 😉.

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [July 29, 2020, 4:20pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/17 "2020-07-29T16:20:53Z")

</div>

[Done](https://github.com/sequelize/sequelize/pull/12568).

Is there a workaround I can use in the meantime?

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [July 31, 2020, 1:37pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/18 "2020-07-31T13:37:44Z")

</div>

Hi @nacho,

Since the bug is at the generation process, a workaround may be to move you backup schema, in order to let Sequelize with only one schema.

---

<div class="post-metadata">

**Author:** ![nacho](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nacho/32/579_2.png) [@nacho](https://community.forestadmin.com/u/nacho)\
**Post date:** [August 3, 2020, 2:19pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/19 "2020-08-03T14:19:10Z")

</div>

Thanks, Sliman. How should I go about this? Do you mean moving it to a different database and then moving it back? I’m a bit hesitant this might break things 😅

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [August 3, 2020, 4:02pm UTC](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725/20 "2020-08-03T16:02:29Z")

</div>

Hi @nacho,

Not sure if that would work, but you could maybe try to `yarn link` your sequelize PR inside your globally installed lumber until it is fixed and merged, then in the lumber generated project ?  
This is far from being a good solution.

Maybe a database dump imported inside a local docker and a removal of the `backup` schema would do the trick ? At least until your PR is merged ?

[Next page](https://community.forestadmin.com/t/cant-connect-to-postgres-db-inside-another-docker-container/725.md?page=2)
