|
15 | 15 | - [Why](#why-dockman) |
16 | 16 | - [Common Errors](#common-errors) |
17 | 17 | - [File Layout](#file-layout) |
| 18 | +- [Env loading](#env-loading) |
18 | 19 | - [Multihost support](#multihost-support) |
19 | 20 | - [Feedback](#feedback) |
20 | 21 | - [Security Considerations](#security-considerations) |
@@ -288,7 +289,8 @@ Dockman will only see top level directories but Git will attempt to load all fil |
288 | 289 | * **Keep stack root clean:** Only include Docker Compose files and relevant configuration files in your stack |
289 | 290 | directory. |
290 | 291 | * **Avoid .gitignore as a workaround**: While you can use .gitignore to exclude files, this is not recommended for |
291 | | - Dockman. The better cleaner practice is to keep only relevant configuration files in your compose root and separate your |
| 292 | + Dockman. The better cleaner practice is to keep only relevant configuration files in your compose root and |
| 293 | + separate your |
292 | 294 | stack definitions from your data directories entirely. |
293 | 295 | * **See also:** [Recommended file layout](#file-layout) for best practices. |
294 | 296 |
|
@@ -331,12 +333,93 @@ stacks/ |
331 | 333 |
|
332 | 334 | Think this is too limiting? Open an [issue](https://github.com/RA341/dockman/issues) and we can argue about it. |
333 | 335 |
|
334 | | -## Multihost Support |
| 336 | +## Env Loading |
335 | 337 |
|
336 | | -> [!IMPORTANT] |
| 338 | +Dockman can automatically discover and load environment files when running your compose setup. |
| 339 | +
|
| 340 | +> [!NOTE] |
| 341 | +> **Only files named `.env` are supported.** |
| 342 | +
|
| 343 | +If the same variable is defined in multiple places, the value from the **higher-precedence** source will overwrite the |
| 344 | +lower one. This makes it easy to override global defaults with project-specific settings. |
| 345 | +
|
| 346 | +Precedence (highest → lowest): |
| 347 | +
|
| 348 | +1. **Subfolder `.env`** - scoped to a specific compose folder |
| 349 | +2. **Root `.env`** - global defaults for everything under the compose root |
| 350 | +3. **OS env vars** - values already defined in your shell/OS environment |
| 351 | +
|
| 352 | +```text |
| 353 | +compose-root/ |
| 354 | + ├─ .env (global) |
| 355 | + └─ subfolder/ |
| 356 | + └─ .env (overrides global) |
| 357 | +``` |
| 358 | + |
| 359 | +> [!Note] |
| 360 | +> These `.env` files are **only for Docker Compose interpolation**. |
337 | 361 | > |
338 | | -> From [v2+](https://github.com/RA341/dockman/releases/tag/v2.0.0) onwards, hosts.yaml method is removed, |
339 | | -> in favour of a easier UI method |
| 362 | +> They are not automatically transferred into the container. |
| 363 | +> |
| 364 | +> Only variables referenced with `${VAR}` in the compose file are substituted. |
| 365 | +
|
| 366 | +Example (interpolation only): |
| 367 | + |
| 368 | +```yaml |
| 369 | +services: |
| 370 | + database: |
| 371 | + image: postgres:15 |
| 372 | + environment: |
| 373 | + POSTGRES_DB: myapp |
| 374 | + POSTGRES_USER: user |
| 375 | + POSTGRES_PASSWORD: password |
| 376 | + volumes: |
| 377 | + - ${TEST}:/var/somepath |
| 378 | + - ${ENVIRONMENT}:/anotherpath/ |
| 379 | + - db_data:/var/lib/postgresql/data |
| 380 | + ports: |
| 381 | + - "5432:5432" |
| 382 | + |
| 383 | +volumes: |
| 384 | + db_data: |
| 385 | +``` |
| 386 | +
|
| 387 | +In this example, `${TEST}` and `${ENVIRONMENT}` are resolved from `.env` |
| 388 | +but are not injected into the container environment automatically. |
| 389 | + |
| 390 | +### Adding Environment Variables to the Container |
| 391 | + |
| 392 | +To actually pass environment variables into the container, you can: |
| 393 | + |
| 394 | +**1. Pass them via `environment`:** |
| 395 | + |
| 396 | +```yaml |
| 397 | +services: |
| 398 | + app: |
| 399 | + image: myapp:latest |
| 400 | + environment: |
| 401 | + APP_ENV: ${ENVIRONMENT} # <- docker compose will replace these before parsing the compose file |
| 402 | + DEBUG: ${DEBUG} |
| 403 | +``` |
| 404 | + |
| 405 | +**2. Or use the `env_file`:** |
| 406 | + |
| 407 | +```yaml |
| 408 | +services: |
| 409 | + app: |
| 410 | + image: myapp:latest |
| 411 | + env_file: |
| 412 | + - ./.env # load sub dir env file |
| 413 | +``` |
| 414 | + |
| 415 | +Where `.env` might look like: |
| 416 | + |
| 417 | +```dotenv |
| 418 | +ENVIRONMENT=production |
| 419 | +DEBUG=false |
| 420 | +``` |
| 421 | + |
| 422 | +## Multihost Support |
340 | 423 |
|
341 | 424 | Dockman's multihost feature lets you manage remote Docker hosts from one centralized interface. |
342 | 425 | Jump between servers, keep your configurations perfectly organized, and deploy across your entire infrastructure |
|
0 commit comments