Skip to content

docker-compose #308

@uniquejava

Description

@uniquejava
~ docker-compose --version
docker-compose version 1.25.4, build 8d51620a
➜  ~ docker --version
Docker version 19.03.8, build afacb8b
➜  ~ docker-compose -f docker-compose-postgres.yml up

First glance

  1. 包含service (一个service可以跑相同image的多个replica)
  2. 可以定义多个containers, networks和volumes
  3. 使用template, variables

v2 vs v3

  1. v2 focus: single-node dev/test
  2. v3 focus: multi-node orchestration
  3. If not using Swarm/K8s, stick to v2

docker-compose.yml (默认文件名)

node.js

version: '2.0'

services:
  web:
    image: sample-01
    build .
    ports:
      - "3000:3000"

mysql

version: '3'
services:
  mysqldb:
    image: mysql:5.7
    container_name: mysqldb
    ports:
      - "3306:3306"
    environment:
     MYSQL_ROOT_PASSWORD: admin
     MYSQL_DATABASE: catalog

docker-compose up

  1. build/pull images(s) if missing
  2. create volume/network/container(s)
  3. starts container(s) in foreground (-d to detach)
  4. --build to always build

docker-compose down

  1. stop and delete network/container(s)
  2. use -v to delete volumes

docker-compose build/stop

  1. many commands take "service" option
  2. build: just build/rebuild image(s) docker-componse build --no-cache 重新执行Dockerfile中的每一行命令
  3. stop: just stop containers don't delete
  4. ps: list "services"
  5. push: images to registry
  6. logs: same as docker CLI
  7. exec: same as docker CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions