View on GitHub

Dashboard

Record development progress of DeliciousFoodEasyOrder.

docker-compose 使用

Compose is a tool for defining and running multi-container Docker applications.

Overview

使用docker-compose,能将多个不同的容器组合起来运行,方便地定义容器间的协作关系。

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Compose works in all environments: production, staging, development, testing, as well as CI workflows.

Using Compose is basically a three-step process:

Define your app’s environment with a Dockerfile so it can be reproduced anywhere.

Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.

Run docker-compose up and Compose starts and runs your entire app.

A docker-compose.yml looks like this:

version: '3'
services:
  web:
    build: .
    ports:
    - "5000:5000"
    volumes:
    - .:/code
    - logvolume01:/var/log
    links:
    - redis
  redis:
    image: redis
volumes:
  logvolume01: {}

Compose has commands for managing the whole lifecycle of your application:

Example 示例

以本项目后台服务器的为例,

version: '3'

services:
  rest-api:
    image: dfeo/rest-api
    networks:
      - net
      - nginx-net
    volumes:
      - /root/mnt/easyorder/static:/go/src/app/static

  db:
    image: "mysql:5.7"
    volumes:
      - /root/mnt/easyorder/mysql/mysql:/var/lib/mysql
      - /root/mnt/easyorder/mysql/init:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: password
    networks:
      - net

networks:
  nginx-net:
    external: true
  net:
    ipam:
      driver: default
      config:
        -
          subnet: 172.18.0.0/16

该文件表明,