豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit f1a6b2f

Browse files
authored
docs(drivers): refresh guide on adding a db driver in docker (#26038)
1 parent ee308fb commit f1a6b2f

File tree

1 file changed

+21
-51
lines changed

1 file changed

+21
-51
lines changed

docs/docs/databases/docker-add-drivers.mdx

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,87 +7,57 @@ version: 1
77

88
## Adding New Database Drivers in Docker
99

10-
Superset requires a Python database driver to be installed for each additional type of database you
11-
want to connect to. When setting up Superset locally via `docker compose`, the drivers and packages
12-
contained in
13-
[requirements.txt](https://github.com/apache/superset/blob/master/requirements.txt) and
14-
[requirements-dev.txt](https://github.com/apache/superset/blob/master/requirements-dev.txt)
15-
will be installed automatically.
10+
Superset requires a Python database driver to be installed for each additional type of database you want to connect to.
1611

17-
In this section, we'll walk through how to install the MySQL connector library. The connector
18-
library installation process is the same for all additional libraries and we'll end this section
19-
with the recommended connector library for each database.
12+
In this example, we'll walk through how to install the MySQL connector library. The connector library installation process is the same for all additional libraries.
2013

2114
### 1. Determine the driver you need
2215

23-
To figure out how to install the [database driver](/docs/databases/installing-database-drivers) of your choice.
16+
Consult the [list of database drivers](/docs/databases/installing-database-drivers) and find the PyPI package needed to connect to your database. In this example, we're connecting to a MySQL database, so we'll need the `mysqlclient` connector library.
2417

25-
In the example, we'll walk through the process of installing a MySQL driver in Superset.
18+
### 2. Install the driver in the container
2619

27-
### 2. Install MySQL Driver
20+
We need to get the `mysqlclient` library installed into the Superset docker container (it doesn't matter if it's installed on the host machine). We could enter the running container with `docker exec -it <container_name> bash` and run `pip install mysqlclient` there, but that wouldn't persist permanently.
2821

29-
As we are currently running inside of a Docker container via `docker compose`, we cannot simply run
30-
`pip install mysqlclient` on our local shell and expect the drivers to be installed within the
31-
Docker containers for superset.
22+
To address this, the Superset `docker compose` deployment uses the convention of a `requirements-local.txt` file. All packages listed in this file will be installed into the container from PyPI at runtime. This file will be ignored by Git for the purposes of local development.
3223

33-
In order to address this, the Superset `docker compose` setup comes with a mechanism for you to
34-
install packages locally, which will be ignored by Git for the purposes of local development. Please
35-
follow these steps:
36-
37-
Create `requirements-local.txt`
24+
Create the file `requirements-local.txt` in a subdirectory called `docker` that exists in the directory with your `docker-compose.yml` or `docker-compose-non-dev.yml` file.
3825

3926
```
40-
# From the repo root...
27+
# Run from the repo root:
4128
touch ./docker/requirements-local.txt
4229
```
4330

44-
Add the driver selected in step above:
31+
Add the driver identified in step above. You can use a text editor or do it from the command line like:
4532

4633
```
4734
echo "mysqlclient" >> ./docker/requirements-local.txt
4835
```
4936

50-
Rebuild your local image with the new driver baked in:
37+
**If you are running a stock (non-customized) Superset image**, you are done. Launch Superset with `docker compose -f docker-compose-non-dev.yml up` and the driver should be present.
5138

52-
```
53-
docker compose build --force-rm
54-
```
39+
You can check its presence by entering the running container with `docker exec -it <container_name> bash` and running `pip freeze`. The PyPI package should be present in the printed list.
5540

56-
After the rebuild of the Docker images is complete (which may take a few minutes) you can relaunch using the following command:
41+
**If you're running a customized docker image**, rebuild your local image with the new driver baked in:
5742

5843
```
59-
docker compose up
44+
docker compose build --force-rm
6045
```
6146

62-
The other option is to start Superset via Docker Compose is using the recipe in `docker-compose-non-dev.yml`, which will use pre-built frontend assets and skip the building of front-end assets:
63-
64-
```
65-
docker compose -f docker-compose-non-dev.yml pull
66-
docker compose -f docker-compose-non-dev.yml up
67-
```
47+
After the rebuild of the Docker images is complete, relaunch Superset by running `docker compose up`.
6848

6949
### 3. Connect to MySQL
7050

71-
Now that you've got a MySQL driver installed locally, you should be able to test it out.
72-
73-
We can now create a Datasource in Superset that can be used to connect to a MySQL instance. Assuming
74-
your MySQL instance is running locally and can be accessed via localhost, use the following
75-
connection string in “SQL Alchemy URI”, by going to Sources > Databases > + icon (to add a new
76-
datasource) in Superset.
51+
Now that you've got a MySQL driver installed in your container, you should be able to connect to your database via the Superset web UI.
7752

78-
For Docker running in Linux:
53+
As an admin user, go to Settings -> Data: Database Connections and click the +DATABASE button. From there, follow the steps on the [Using Database Connection UI page](https://superset.apache.org/docs/databases/db-connection-ui).
7954

80-
```
81-
mysql://mysqluser:mysqluserpassword@localhost/example?charset=utf8
82-
```
55+
Consult the page for your specific database type in the Superset documentation to determine the connection string and any other parameters you need to input. For instance, on the [MySQL page](https://superset.apache.org/docs/databases/mysql), we see that the connection string to a local MySQL database differs depending on whether the setup is running on Linux or Mac.
8356

84-
For Docker running in OSX:
57+
Click the “Test Connection” button, which should result in a popup message saying, "Connection looks good!".
8558

86-
```
87-
mysql://mysqluser:mysqluserpassword@docker.for.mac.host.internal/example?charset=utf8
88-
```
59+
### 4. Troubleshooting
8960

90-
Then click “Test Connection”, which should give you an “OK” message. If not, please look at your
91-
terminal for error messages, and reach out for help.
61+
If the test fails, review your docker logs for error messages. Superset uses SQLAlchemy to connect to databases; to troubleshoot the connection string for your database, you might start Python in the Superset application container or host environment and try to connect directly to the desired database and fetch data. This eliminates Superset for the purposes of isolating the problem.
9262

93-
You can repeat this process for every database you want superset to be able to connect to.
63+
Repeat this process for each different type of database you want Superset to be able to connect to.

0 commit comments

Comments
 (0)