# Accessing to the database from outside the container

**URL:** https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257
**Category:** Self-hosting
**Created:** [4 juni 2016 om 19:25 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257 "2016-06-04T19:25:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Chopper](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chopper/32/57073_2.png) [@Chopper](https://meta.discourse.org/u/Chopper)
#### Post date: [4 juni 2016 om 19:25 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257/1 "2016-06-04T19:25:40Z")

</div>

How can i access to the database from ouside the container but in the same server (local)

I open the port in app.yml

```
expose:
  - "4002:5432" #postgres

```

Try to connect from outside with

```plaintext
psql -h 127.17.0.1 -p 4002 -d postgres -U postgres -p ''
psql: could not connect to server: Connection refused
        Is the server running on host "127.17.0.1" and accepting
        TCP/IP connections on port 5432?

```

What i’m missing ?

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [5 juni 2016 om 02:57 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257/2 "2016-06-05T02:57:00Z")

</div>

Did you rebuild the container after editing `app.yml`? That’s necessary to make changes effective in the running system.

---

<div class="post-metadata">

### Author: ![Chopper](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chopper/32/57073_2.png) [@Chopper](https://meta.discourse.org/u/Chopper)
#### Post date: [5 juni 2016 om 10:08 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257/3 "2016-06-05T10:08:55Z")

</div>

Yep multiple time ! 😩

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [6 juni 2016 om 02:44 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257/4 "2016-06-06T02:44:04Z")

</div>

I can’t reproduce the problem. If I do what you describe, it Works For Me. Presumably there’s some other sort of customisation you’ve applied, but not mentioned, that’s causing the problem.

Incidentally, since you’re running on the same machine, you don’t have to expose the port, you can just connect to the Docker-internal IP (`172.17.0.<X>`) on port 5432 and it should work.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [28 januari 2019 om 12:10 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257/7 "2019-01-28T12:10:57Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [28 januari 2019 om 13:56 UTC](https://meta.discourse.org/t/accessing-to-the-database-from-outside-the-container/45257/8 "2019-01-28T13:56:29Z")

</div>


