layout: 2017/sheet
prism_languages: [yaml]
weight: -1
-updated: 2018-06-26
+updated: 2020-01-01
---
### Basic example
services:
web:
- build: .
+ build:
# build from Dockerfile
- context: ./Path
- dockerfile: Dockerfile
+ context: ./Path
+ dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- db
```
+```yaml
+ # make sure `db` is healty before starting
+ # and db-init completed without failure
+ depends_on:
+ db:
+ condition: service_healthy
+ db-init:
+ condition: service_completed_successfully
+```
+
### Other options
```yaml
- ./_data:/var/lib/mysql
```
+```yaml
+ # automatically restart container
+ restart: unless-stopped
+ # always, on-failure, no (default)
+```
+
## Advanced features
{: .-three-column}
- project_db_1:mysql
```
+### Healthcheck
+
+```yaml
+ # declare service healthy when `test` command succeed
+ healthcheck:
+ test: ["CMD", "curl", "-f", "http://localhost"]
+ interval: 1m30s
+ timeout: 10s
+ retries: 3
+ start_period: 40s
+```
+
### Hosts
```yaml
external:
name: frontend
```
+
+### Volume
+
+```yaml
+# mount host paths or named volumes, specified as sub-options to a service
+ db:
+ image: postgres:latest
+ volumes:
+ - "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
+ - "dbdata:/var/lib/postgresql/data"
+
+volumes:
+ dbdata:
+```
+
+### User
+
+```yaml
+# specifying user
+user: root
+```
+
+```yaml
+# specifying both user and group with ids
+user: 0:0
+```