OSDN Git Service

Regular updates
[twpd/master.git] / docker-compose.md
index 84d554c..210fe1c 100644 (file)
@@ -4,7 +4,7 @@ category: Devops
 layout: 2017/sheet
 prism_languages: [yaml]
 weight: -1
-updated: 2018-06-26
+updated: 2020-01-01
 ---
 
 ### Basic example
@@ -15,10 +15,10 @@ version: '2'
 
 services:
   web:
-    build: .
+    build:
     # build from Dockerfile
-    context: ./Path
-    dockerfile: Dockerfile
+      context: ./Path
+      dockerfile: Dockerfile
     ports:
      - "5000:5000"
     volumes:
@@ -133,6 +133,16 @@ web:
     - 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
@@ -148,6 +158,12 @@ web:
     - ./_data:/var/lib/mysql
 ```
 
+```yaml
+  # automatically restart container
+  restart: unless-stopped
+  # always, on-failure, no (default)
+```
+
 ## Advanced features
 {: .-three-column}
 
@@ -190,6 +206,18 @@ services:
       - 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
@@ -216,3 +244,29 @@ networks:
     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
+```