Files
WGDashboard/docker/README.md
T

288 lines
11 KiB
Markdown
Raw Normal View History

2024-11-07 23:54:48 +08:00
# WGDashboard Docker Explanation:
2025-04-25 09:27:07 +02:00
Author: @DaanSelen<br>
2024-11-07 23:54:48 +08:00
This document delves into how the WGDashboard Docker container has been built.<br>
2025-04-25 09:27:07 +02:00
Of course there are two stages (simply said), one before run-time and one at/after run-time.<br>
The `Dockerfile` describes how the container image is made, and the `entrypoint.sh` is executed after the container is started. <br>
In this example, [WireGuard](https://www.wireguard.com/) is integrated into the container itself, so it should be a run-and-go(/out-of-the-box) experience.<br>
2024-11-07 23:54:48 +08:00
For more details on the source-code specific to this Docker image, refer to the source files, they have lots of comments.
2025-04-25 09:27:07 +02:00
<br>
<img
src="https://wgdashboard-resources.tor1.cdn.digitaloceanspaces.com/Logos/Logo-2-Rounded-512x512.png"
alt="WG-Dashboard Logo"
title="WG-Dashboard Logo"
style="display: block; margin: 0 auto;"
width="150"
height="150"
/>
<br>
2024-11-07 23:54:48 +08:00
To get the container running you either pull the pre-made image from a remote repository, there are 2 official options.<br>
- ghcr.io/wgdashboard/wgdashboard:<tag>
- docker.io/donaldzou/wgdashboard:<tag>
> tags should be either: latest, main, <version>, <branch-name> (if built) or <commit-sha>.
From there either use the environment variables described below as parameters or use the Docker Compose file: `compose.yaml`.<br>
Be careful, the default generated WireGuard configuration file uses port 51820/udp. So make sure to use this port if you want to use it out of the box.<br>
Otherwise edit the configuration file in WGDashboard under `Configuration Settings` -> `Edit Raw Configuration File`.
> Otherwise you need to enter the container and edit: `/etc/wireguard/wg0.conf`.
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
# WGDashboard: 🐳 Docker Deployment Guide
2024-11-07 23:54:48 +08:00
To run the container, you can either pull the image from the Github Container Registry (ghcr.io), Docker Hub (docker.io) or build it yourself. The image is available at:
2025-04-25 09:27:07 +02:00
> `docker.io` is in most cases automatically resolved by the Docker application. Therefor you can ofter specify: `donaldzou/wgdashboard:latest`
2025-04-25 09:27:07 +02:00
### 🔧 Quick Docker Run Command
Here's an example to get it up and running quickly:
```bash
2024-11-07 23:54:48 +08:00
docker run -d \
--name wgdashboard \
--restart unless-stopped \
-p 10086:10086/tcp \
-p 51820:51820/udp \
--cap-add NET_ADMIN \
ghcr.io/wgdashboard/wgdashboard:latest
2024-11-07 23:54:48 +08:00
```
2025-04-25 09:27:07 +02:00
> ⚠️ The default WireGuard port is `51820/udp`. If you change this, update the `/etc/wireguard/wg0.conf` accordingly.
---
### 📦 Docker Compose Alternative (see the [compose file](./compose.yaml))
2025-04-25 09:27:07 +02:00
You can also use Docker Compose for easier configuration:
2024-11-07 23:54:48 +08:00
```yaml
services:
wgdashboard:
image: ghcr.io/wgdashboard/wgdashboard:latest
2024-11-07 23:54:48 +08:00
restart: unless-stopped
container_name: wgdashboard
ports:
- 10086:10086/tcp
- 51820:51820/udp
2024-11-07 23:54:48 +08:00
volumes:
- aconf:/etc/amnezia/amneziawg
2024-11-07 23:54:48 +08:00
- conf:/etc/wireguard
- data:/data
2024-11-07 23:54:48 +08:00
cap_add:
- NET_ADMIN
volumes:
aconf:
2024-11-07 23:54:48 +08:00
conf:
data:
```
2025-04-25 09:27:07 +02:00
> 📁 You can customize the **volume paths** on the host to fit your needs. The example above uses Docker volumes.
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
---
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
## 🔄 Updating the Container
2024-11-07 23:54:48 +08:00
Updating the WGDashboard container should be through 'The Docker Way' - by pulling the newest/newer image and replacing this old one.
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
---
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
## ⚙️ Environment Variables
2024-11-07 23:54:48 +08:00
2025-09-15 13:09:14 +03:00
| Variable | Accepted Values | Default | Example | Description |
| ------------------ | ---------------------------------------- | ----------------------- | --------------------- | ----------------------------------------------------------------------- |
| `dynamic_config` | true, yes, false, no | `true` | `true` or `no` | Turns on or off the dynamic configuration feature, on by default for Docker |
2025-09-15 13:09:14 +03:00
| `tz` | Timezone | `Europe/Amsterdam` | `America/New_York` | Sets the container's timezone. Useful for accurate logs and scheduling. |
| `global_dns` | IPv4 and IPv6 addresses | `9.9.9.9` | `8.8.8.8`, `1.1.1.1` | Default DNS for WireGuard clients. |
| `public_ip` | Public IP address | Retrieved automatically | `253.162.134.73` | Used to generate accurate client configs. Needed if container is NATd. |
| `wgd_port` | Any port that is allowed for the process | `10086` | `443` | This port is used to set the WGDashboard web port. |
| `username` | Any nonempty string | `-` | `admin` | Username for the WGDashboard web interface account. |
| `password` | Any nonempty string | `-` | `s3cr3tP@ss` | Password for the WGDashboard web interface account (stored hashed). |
| `enable_totp` | `true`, `false` | `true` | `false` | Enable TOTPbased twofactor authentication for the account. |
2026-06-06 04:54:35 +12:00
| `wg_autostart` | Wireguard interface name | `- ` | `wg0` | Automatically start the specified WireGuard interface when the container starts |
2025-09-15 13:09:14 +03:00
| `email_server` | SMTP server address | `-` | `smtp.gmail.com` | SMTP server for sending email notifications. |
| `email_port` | SMTP port number | `-` | `587` | Port for connecting to the SMTP server. |
| `email_encryption` | `TLS`, `SSL`, etc. | `-` | `TLS` | Encryption method for email communication. |
| `email_username` | Any non-empty string | `-` | `user@example.com` | Username for SMTP authentication. |
| `email_password` | Any non-empty string | `-` | `app_password` | Password for SMTP authentication. |
| `email_from` | Valid email address | `-` | `noreply@example.com` | Email address used as the sender for notifications. |
| `email_template` | Path to template file | `-` | `your-template` | Custom template for email notifications. |
2026-01-29 13:32:03 +01:00
| `database_type` | `sqlite`, `postgresql`, `mariadb+mariadbconnector`, etc. | `-` | `postgresql` | Type of [sqlalchemy database engine](https://docs.sqlalchemy.org/en/21/core/engines.html). |
| `database_host` | Any non-empty string | `-` | `localhost` | IP-Address or hostname of the SQL-database server. |
| `database_port` | Any non-empty string (or int for port) | `-` | `5432` | Port for the database communication. |
| `database_username`| Valid database username | `-` | `database_user` | Database user username. |
| `database_password`| Valid database password | `-` | `database_password` | Database user password. |
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
---
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
## 🔐 Port Forwarding Note
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
When using multiple WireGuard interfaces, remember to **open their respective ports** on the host.
2024-11-08 00:29:01 +08:00
2025-04-25 09:27:07 +02:00
Examples:
```yaml
# Individual mapping
- 51821:51821/udp
2024-11-08 00:29:01 +08:00
2025-04-25 09:27:07 +02:00
# Or port range
- 51820-51830:51820-51830/udp
```
2024-11-07 23:54:48 +08:00
2025-04-25 09:27:07 +02:00
> 🚨 **Security Tip:** Only expose ports you actually use.
---
## 🛠️ Building the Image Yourself
To build from source:
```bash
2025-09-11 10:38:30 +08:00
git clone https://github.com/WGDashboard/WGDashboard.git
2025-04-25 09:27:07 +02:00
cd WGDashboard
docker build . -f docker/Dockerfile -t yourname/wgdashboard:latest
```
Example output:
2024-11-07 23:54:48 +08:00
```shell
2025-04-25 09:27:07 +02:00
docker images
2024-11-07 23:54:48 +08:00
REPOSITORY TAG IMAGE ID CREATED SIZE
2025-04-25 09:27:07 +02:00
yourname/wgdashboard latest c96fd96ee3b3 42 minutes ago 314MB
2024-11-07 23:54:48 +08:00
```
2025-04-25 09:27:07 +02:00
---
## 🧱 Dockerfile Overview
Here's a brief overview of the Dockerfile stages used in the image build:
### 1. **Build Tools & Go Compilation**
```Dockerfile
FROM golang:1.24 AS compiler
WORKDIR /go
RUN apt-get update && apt-get install -y ...
RUN git clone ... && make
...
```
### 2. **Binary Copy to Scratch**
```Dockerfile
FROM scratch AS bins
COPY --from=compiler /go/amneziawg-go/amneziawg-go /amneziawg-go
...
```
### 3. **Final Alpine Container Setup**
```Dockerfile
FROM alpine:latest
COPY --from=bins ...
RUN apk update && apk add --no-cache ...
COPY ./src ${WGDASH}/src
COPY ./docker/entrypoint.sh /entrypoint.sh
...
EXPOSE 10086
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
```
---
## 🚀 Entrypoint Overview
### Major Functions:
- **`ensure_installation`**: Sets up the app, database, and Python environment.
- **`set_envvars`**: Writes `wg-dashboard.ini` and applies environment variables.
- **`start_core`**: Starts the main WGDashboard service.
- **`ensure_blocking`**: Tails the error log to keep the container process alive.
---
## ✅ Final Notes
- Use `docker logs wgdashboard` for troubleshooting.
- Access the web interface via `http://your-ip:10086` (or whichever port you specified in the compose).
- The first time run will auto-generate WireGuard keys and configs (configs are generated from the template).
## 🧑‍💻 Local Development with Docker
You can develop against WGDashboard locally by mounting the `src/` directory into the container. This lets you edit Python and frontend code on your host and see changes reflected immediately (with a service restart for Python).
Create a `docker/compose-local.yaml` alongside the existing `compose.yaml`:
```yaml
services:
wgdashboard:
image: ghcr.io/wgdashboard/wgdashboard:latest
restart: unless-stopped
container_name: wgdashboard
ports:
- 10086:10086/tcp
- 51820:51820/udp
volumes:
- aconf:/etc/amnezia/amneziawg
- conf:/etc/wireguard
- data:/data
# Mount local src for live editing
- ../src:/opt/wgdashboard/src
# Keep venv in a named volume so it isn't overwritten by the mount
- venv:/opt/wgdashboard/src/venv
cap_add:
- NET_ADMIN
volumes:
aconf:
conf:
data:
venv:
```
The key additions compared to the production compose file:
- `../src:/opt/wgdashboard/src` — mounts your local `src/` directory into the container so code changes are reflected without rebuilding the image.
- `venv:/opt/wgdashboard/src/venv` — keeps the Python virtual environment in a named Docker volume. Without this, the host mount would overwrite the venv created during image build.
To start the development container:
```bash
cd docker
docker compose -f compose-local.yaml up -d
```
After editing Python files (e.g. `src/dashboard.py`), restart the container to pick up changes:
```bash
docker restart wgdashboard
```
For frontend changes, install dependencies and rebuild the Vue app on your host:
```bash
cd src/static/app
npm install
npm run build
```
Then restart the container so it serves the updated dist files:
```bash
docker restart wgdashboard
```
---
2024-11-07 23:54:48 +08:00
## Closing remarks:
For feedback please submit an issue to the repository. Or message dselen@nerthus.nl.