简体   繁体   English

Docker Volume:持久化数据以供跨远程主机访问

[英]Docker Volume: Persist data for access across remote hosts

Question

How do you access a volume across remote hosts so the data persists even if the instance goes down? 您如何跨远程主机访问卷,以便即使实例发生故障,数据也能持久保存?

My Setup 我的设定

This was setup on a Digital Ocean droplet with - 这是在Digital Ocean小滴上设置的-

  • Create the docker machine from the cli 从CLI创建Docker机器
  • eval $(docker-machine env <name_of_machine>)
  • docker-compose -f production.yml build
  • docker-compose -f production.yml up

Docker-Compose file Docker-Compose文件

My Postgres service is writing data to two different volumes - one for the database, and the other for backups. 我的Postgres服务正在将数据写入两个不同的卷-一个用于数据库,另一个用于备份。

version: '3'

volumes:
  production_postgres_data: {}
  production_postgres_data_backups: {}
  production_caddy: {}

services:

  django: &django
    build:
      context: .
      dockerfile: ./compose/production/django/Dockerfile
    image: mom_production_django
    depends_on:
      - postgres
      - redis
    env_file:
      - ./.envs/.production/.django
      - ./.envs/.production/.postgres
    command: /start

  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    image: mom_production_postgres
    volumes:
      - production_postgres_data:/var/lib/postgresql/data
      - production_postgres_data_backups:/backups
    env_file:
      - ./.envs/.production/.postgres

Concern 关心

These volumes are within that droplet, and my concern is that if anything happens to the droplet, the volumes will go with it. 这些体积在该小滴内,而我担心的是,如果小滴发生任何变化,这些体积将随之而来。

So how do you create a volume that can persist and be shared across remote hosts or in this case droplets? 那么,如何创建一个可以持久保存并在远程主机之间共享的卷?

You need to add persistence block storage. 您需要添加持久性块存储。 For reference please refer the link below. 有关参考,请参考下面的链接。 add persistence volume support 添加持久性卷支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM