简体   繁体   中英

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 -

  • Create the docker machine from the cli
  • eval $(docker-machine env <name_of_machine>)
  • docker-compose -f production.yml build
  • docker-compose -f production.yml up

Docker-Compose file

My Postgres service is writing data to two different volumes - one for the database, and the other for backups.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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