|
1 | 1 | ---
|
2 | 2 | title: Docker Service
|
3 |
| -desc: |
| 3 | +desc: Comprehensive guide to using Docker on Zerops with VM-based environments. Includes configuration examples and best practices. |
4 | 4 | ---
|
5 | 5 |
|
6 | 6 | import UnorderedCodeList from '@site/src/components/UnorderedCodeList';
|
@@ -91,6 +91,52 @@ For projects using Docker Compose, additional configuration is required:
|
91 | 91 | network_mode: host
|
92 | 92 | ```
|
93 | 93 |
|
| 94 | +3. **Start Command**: |
| 95 | + ```yaml title="zerops.yml" |
| 96 | + run: |
| 97 | + start: docker compose up --force-recreate |
| 98 | + ``` |
| 99 | + |
| 100 | +### Environment Variables |
| 101 | + |
| 102 | +When using Docker services, there's an additional layer to consider since environment variables defined in Zerops must be explicitly passed to your Docker containers. |
| 103 | + |
| 104 | +#### 1. Defining Variables in Zerops |
| 105 | + |
| 106 | +Define your environment variables in the `run.envVariables` section of your `zerops.yml` (example uses [referenced](/features/env-variables#referencing-variables) variables): |
| 107 | + |
| 108 | +```yaml title="zerops.yml" |
| 109 | +zerops: |
| 110 | + - setup: app |
| 111 | + run: |
| 112 | + envVariables: |
| 113 | + DB_HOST: ${db_hostname} |
| 114 | + DB_PORT: ${db_port} |
| 115 | +``` |
| 116 | + |
| 117 | +#### 2. Passing Variables to Docker Containers |
| 118 | + |
| 119 | +For single containers, pass variables using the `-e` flag: |
| 120 | + |
| 121 | +```yaml title="zerops.yml" |
| 122 | +run: |
| 123 | + prepareCommands: |
| 124 | + - docker image pull my-application:latest |
| 125 | + start: docker run -e DB_HOST -e DB_PORT --network=host my-application:latest |
| 126 | +``` |
| 127 | + |
| 128 | +For Docker Compose setups, pass environment variables in your `docker-compose.yml`: |
| 129 | + |
| 130 | +```yaml title="docker-compose.yml" |
| 131 | +services: |
| 132 | + api: |
| 133 | + image: my-application:latest |
| 134 | + network_mode: host |
| 135 | + environment: |
| 136 | + - DB_HOST |
| 137 | + - DB_PORT |
| 138 | +``` |
| 139 | + |
94 | 140 | ## Implementation Examples
|
95 | 141 |
|
96 | 142 | ### Single Container
|
@@ -187,4 +233,4 @@ Docker services on Zerops have specific scaling characteristics that differ from
|
187 | 233 | - Still supports multiple containers through `minContainers` and `maxContainers`
|
188 | 234 | - Consider breaking large services into smaller components
|
189 | 235 | - Implement proper health checks for reliable scaling
|
190 |
| -- Use horizontal scaling when possible to avoid VM restarts |
| 236 | +- Use horizontal scaling when possible to avoid VM restarts |
0 commit comments