Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Docker installation instructions based on the updated installation plan #3212

Merged
merged 12 commits into from
Sep 25, 2023
4 changes: 2 additions & 2 deletions docs/docs/configuration/env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This page contains all available environment variables supported by Mathesar. Se

## Backend configuration {: #backend}

### `SECRET_KEY`
### `SECRET_KEY` {: #secret_key}

- **Description**: A unique random string used by Django for cryptographic signing ([see Django docs](https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-SECRET_KEY)).
- **Format**: A 50 character string
Expand All @@ -28,7 +28,7 @@ This page contains all available environment variables supported by Mathesar. Se
- `https://mathesar.example.com` - contains HTTPS protocol
- `localhost/, 35.188.184.125` - contains trailing slash after `localhost`

### `DJANGO_DATABASE_URL`
### `DJANGO_DATABASE_URL` {: #dj_db}

- **Description**: A Postgres connection string of the database used for **Mathesar's internal usage**.
- **Format**:`postgres://user:password@hostname:port/database_name`
Expand Down
83 changes: 73 additions & 10 deletions docs/docs/installation/docker/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Install Mathesar web server via Docker
# Install Mathesar via Docker

Use our [official Docker image](https://hub.docker.com/r/mathesar/mathesar-prod/tags): `mathesar/mathesar-prod:latest` hosted on Docker Hub to run Mathesar.

!!! warning "Limitations"
This installation procedure is intended for users who want to quickly run Mathesar on their local machine without exposing it to the internet.

For now, please use the [Docker Compose installation documentation](../docker-compose/index.md) if you plan to expose Mathesar to the internet. We will provide more information on how to use this installation method for production servers [soon](https://github.com/centerofci/mathesar/issues/3122).

- You need [Docker](https://docs.docker.com/get-docker/).
- We have tested with Docker v23. Older versions may not work.
- You need permission to run Docker containers.

## Prerequisites

Expand All @@ -19,6 +17,7 @@ You should have permission to run Docker containers on the system.
### Software
You'll need to install **[Docker](https://docs.docker.com/desktop/)** v23+


## Installation Steps

1. Run the Mathesar Docker Image
Expand All @@ -35,25 +34,82 @@ You'll need to install **[Docker](https://docs.docker.com/desktop/)** v23+
--restart unless-stopped \
mathesar/mathesar-prod:latest
```

The above command creates a Docker container containing the Mathesar server running on the `localhost` and listening on port `8000`. It also:

- Creates three [named Docker volumes](https://docs.docker.com/storage/volumes/)
- Creates four [named Docker volumes](https://docs.docker.com/storage/volumes/)
- `static` for storing static assets like CSS, js files
- `media` for storing user-uploaded media files
- `postgresql_data` for storing database related files
- `postgresql_config` for storing database config related files
- Sets the container name as `mathesar_service` using the `--name` parameter, runs the container in a detached mode using the `--detach` parameter, and binds the port `8000` to the `localhost`. Refer to [Docker documentation](https://docs.docker.com/engine/reference/commandline/run/#options) for additional configuration options.

1. Verify if the Mathesar server is running successfully:
```bash
docker logs -f mathesar_service
```

!!! warning
If you are testing Mathesar on a local machine, you can go to the next step for setting up Mathesar. But if you are hosting on a server or looking for a production setup, please take a look at [additional configurations](#configuration) before setting up Mathesar.

1. Set up your user account

Mathesar is now installed! You can use it by visiting `localhost` or the domain you've set up.
Mathesar is now installed! You can use it by visiting `http://localhost:8000` or the domain you've set up.

The first time you open Mathesar, follow the instructions on screen to set up an admin user account and connect to a user database.


## Configuring Mathesar {:#configuration}

### Using a domain name {:#domain-name}

If you are accessing Mathesar using a domain name, you need to add it to the list of domains Mathesar can accept requests from. This can be accomplished by setting the [ALLOWED_HOSTS](../../configuration/env-variables.md#allowed_hosts) environment variable

```bash
docker run \
-e ALLOWED_HOSTS='mathesar.example.com' \
# OTHER ARGS HERE
mathesar/mathesar-prod:latest
```

### Hosting on default port 80

The command used in the quick start section will run Mathesar on port 8000, so you will have to access it on `http://<domain-name>:8000`. If you wish to access Mathesar without adding any port suffix like `http://<domain-name>`, you need to bind it to port 80

You'll be prompted to set up an admin user account the first time you open Mathesar. Just follow the instructions on screen.
```bash
docker run \
-p 80:8000 \
# OTHER ARGS HERE
mathesar/mathesar-prod:latest
```

### Using a remote Postgres server for the internal database

!!! info
We strongly recommend using this setup for stateless deployments when scaling horizontally, because by default the data is stored in the same server on which Mathesar is running. This data will be lost if the server is deleted.

The docker image contains a Postgres server which is used by default. If you want Mathesar to use a remote database as its internal database for storing its metadata, you need to set the remote database credentials to the [DJANGO_DATABASE_URL](../../configuration/env-variables.md#dj_db) environment variable.

```bash
docker run \
-e DJANGO_DATABASE='postgres://user:password@hostname:port/database_name' \
# OTHER ARGS HERE
mathesar/mathesar-prod:latest
```

### Using a custom secret key

By default, the docker image uses a default secret key. The default key should only be used when testing and is not recommended when exposing Mathesar to the outside world.

- Refer to the [SECRET_KEY](../../configuration/env-variables.md#secret_key) for information on how to get your own secret key.
- Pass the key as an environment variable to the docker image.

```bash
docker run \
-e SECRET_KEY='<replace with a random 50 character string>' \
# OTHER ARGS HERE
mathesar/mathesar-prod:latest
```

## Upgrading Mathesar {:#upgrade}

Expand Down Expand Up @@ -101,3 +157,10 @@ You'll need to install **[Docker](https://docs.docker.com/desktop/)** v23+
```

{% include 'snippets/uninstall-schemas.md' %}


## Troubleshooting

### 400 Bad request

If you are getting `400 (Bad request)` when visiting Mathesar using a domain name or an IP address, it might be happening due to the domain name not being correctly whitelisted. Follow the instructions for [accessing using a domain name](#domain-name).
19 changes: 19 additions & 0 deletions docs/docs/user-guide/glossary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Glossary

## Internal database {:#internal-db}

The "internal database" holds Mathesar-specific _metadata_ about the actual data (which lives in the [user database](#user-db)). Examples of such metadata include:

- Exploration definitions
- Column display formatting settings
- Record summary template customizations
- Custom column ordering

Each Mathesar installation requires one and only one internal database, and PostgreSQL and SQLite are both supported.

## User database {:#user-db}

The data you see within Mathesar lives in the "user database", which must use PostgreSQL. Each Mathesar installation can connect to multiple user databases, potentially on different servers.

Mathesar also uses an [internal database](#internal-db) to store metadata.

1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nav:
- Importing data: user-guide/importing-data.md
- Syncing database changes: user-guide/syncing-db.md
- Users & access levels: user-guide/users.md
- Glossary: user-guide/glossary.md

plugins:
- search:
Expand Down