如何将 EC2 实例中 运行 的 docker 卷挂载到 EBS 卷?这样做的步骤是什么?

How to mount docker volume which is running in EC2 instance to EBS volume? What are the steps for that?

目前 ec2 实例是 运行,docker 容器内是 运行。 我在 EC2 实例中有 2 个容器 运行。 1 - 应用程序容器。 2 - 数据库(CouchDb)容器。 我需要将数据库中的数据存储到 EBS 卷中。 我有一个 docker-compose 文件,我正在使用 'docker-compose up' 命令启动容器。

version: '2.1'
services:
  web:
    build: .
    ports:
     - "4200:4200"
     - "7020:7020"
    depends_on:
      couchdb:
        condition: "service_healthy"
    volumes:
      - ./app:/usr/src/app/app
  couchdb:
    image: "couchdb:1.7.1"
    ports:
     - "5984:5984"
    healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost:5984/"]
        interval: 10s
        timeout: 90s
        retries: 9

您需要将 EC2 实例目录与 CouchDB 容器绑定。

在哪里存储数据

Important note: There are several ways to store data used by applications that run in Docker containers. We encourage users of the couchdb images to familiarize themselves with the options available

Create a data directory on a suitable volume on your host system, e.g. /home/ec2-user/data. Start your couchdb container like this:

$ docker run --name mycouchdb -v /home/ec2-user/data:/opt/couchdb/data -d couchdb:tag

The -v /home/ec2-user/data:/opt/couchdb/data part of the command mounts the /home/ec2-user/data directory from the underlying host system as /opt/couchdb/data inside the container, where CouchDB by default will write its data files.

CouchDB Store Data

更新:

在docker-compose的情况下

  couchdb:
    image: "couchdb:1.7.1"
    volumes:
      - /home/ec2-user/data:/opt/couchdb/data
    ports:
     - "5984:5984"