docker-compose: Update with more info

This commit is contained in:
Rico Sta. Cruz 2018-06-26 22:45:48 +08:00
parent ff19f0154b
commit bcfb8d8369
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 50 additions and 9 deletions

View File

@ -4,7 +4,7 @@ category: Devops
layout: 2017/sheet layout: 2017/sheet
prism_languages: [yaml] prism_languages: [yaml]
weight: -1 weight: -1
updated: 2018-03-17 updated: 2018-06-26
--- ---
### Basic example ### Basic example
@ -46,60 +46,101 @@ docker-compose down
``` ```
## Reference ## Reference
{: .-one-column} {: .-three-column}
### Building
```yaml ```yaml
web: web:
# build from Dockerfile # build from Dockerfile
build: . build: .
```
```yaml
# build from custom Dockerfile
build:
context: ./dir
dockerfile: Dockerfile.dev
```
```yaml
# build from image # build from image
image: ubuntu image: ubuntu
image: ubuntu:14.04 image: ubuntu:14.04
image: tutum/influxdb image: tutum/influxdb
image: example-registry:4000/postgresql image: example-registry:4000/postgresql
image: a4bc65fd image: a4bc65fd
```
### Ports
```yaml
ports: ports:
- "3000" - "3000"
- "8000:80" # guest:host - "8000:80" # guest:host
```
```yaml
# expose ports to linked services (not to host)
expose: ["3000"]
```
### Commands
```yaml
# command to execute # command to execute
command: bundle exec thin -p 3000 command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000] command: [bundle, exec, thin, -p, 3000]
```
```yaml
# override the entrypoint # override the entrypoint
entrypoint: /app/start.sh entrypoint: /app/start.sh
entrypoint: [php, -d, vendor/bin/phpunit] entrypoint: [php, -d, vendor/bin/phpunit]
```
### Environment variables
```yaml
# environment vars # environment vars
environment: environment:
RACK_ENV: development RACK_ENV: development
environment: environment:
- RACK_ENV=development - RACK_ENV=development
```
```yaml
# environment vars from file # environment vars from file
env_file: .env env_file: .env
env_file: [.env, .development.env] env_file: [.env, .development.env]
```
# expose ports to linked services (not to host) ### Dependencies
expose: ["3000"]
# make this service extend another
extends:
file: common.yml # optional
service: webapp
```yaml
# makes the `db` service available as the hostname `database` # makes the `db` service available as the hostname `database`
# (implies depends_on) # (implies depends_on)
links: links:
- db:database - db:database
- redis - redis
```
```yaml
# make sure `db` is alive before starting # make sure `db` is alive before starting
depends_on: depends_on:
- db - db
```
### Other options
```yaml
# make this service extend another
extends:
file: common.yml # optional
service: webapp
```
```yaml
volumes: volumes:
- /var/lib/mysql - /var/lib/mysql
- ./_data:/var/lib/mysql - ./_data:/var/lib/mysql