Skip to content

Commit

Permalink
docs: add instructions for how to connect to local database from dock…
Browse files Browse the repository at this point in the history
…er container (apache#15936)

* Update installation instructions for docker

Update installation instructions to include a section on
connecting to local db via superset running in docker container.

Newcomers may have trouble in this part because it involves
knowing about some docker internal details, as well as
google search doesn't bring many directly useful results.

If it's a commonly occurring issue among new comers,
we may accept this commit.

* Update index.mdx

Add a caution regarding changing database config to allow public incoming.
Add a note that mac users may skip configuring database.
Spelling mistake fix.
Style fix, "Superset" is now in title case.
  • Loading branch information
sarthak authored Aug 2, 2021
1 parent 6095978 commit 31d79ff
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/src/pages/docs/installation/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ username: admin
```bash
password: admin
```


### 5. Connecting your local database instance to superset

When running Superset using `docker` or `docker-compose` it runs in its own docker container, as if the Superset was running in a separate machine entirely. Therefore attempts to connect to your local database with hostname `localhost` won't work as `localhost` refers to the docker container Superset is running in, and not your actual host machine. Fortunately, docker provides an easy way to access network resources in the host machine from inside a container, and we will leverage this capability to connect to our local database instance.

Here the instructions are for connecting to postgresql (which is running on your host machine) from Superset (which is running in its docker container). Other databases may have slightly different configurations but gist would be same and boils down to 2 steps -

1. **(Mac users may skip this step)** Configuring the local postgresql/database instance to accept public incoming connections. By default postgresql only allows incoming connections from `localhost` only, but re-iterating once again, `localhosts` are different for host machine and docker container. For postgresql this involves make one-line changes to the files `postgresql.conf` and `pg_hba.conf`, you can find helpful links tailored to your OS / PG version on the web easily for this task. For docker it suffices to only whitelist IPs `172.0.0.0/8` instead of `*`, but in any case you are *warned* that doing this in a production database *may* have disastrous consequences as you are opening your database to the public internet.
2. Instead of `localhost`, try using `host.docker.internal` (Mac users) or `172.18.0.1` (Linux users) as the host name when attempting to connect to the database. This is docker internal detail, what is happening is that in Mac systems docker creates a dns entry for the host name `host.docker.internal` which resolves to the correct address for the host machine, whereas in linux this is not the case (at least by default). If neither of these 2 hostnames work then you may want to find the exact host name you want to use, for that you can do `ifconfig` or `ip addr show` and look at the IP address of `docker0` interface that must have been created by docker for you. Alternately if you don't even see the `docker0` interface try (if needed with sudo) `docker network inspect bridge` and see if there is an entry for `"Gateway"` and note the IP address.

0 comments on commit 31d79ff

Please sign in to comment.