【问题标题】:Named volume not being created in docker未在 docker 中创建命名卷
【发布时间】:2020-07-10 12:24:01
【问题描述】:

我正在尝试创建 django/nginx/gunicorn/postgres docker-compose 配置。

每次我调用 docker-compose down 时,我都注意到我的 postgres 数据库正在被擦除。我做了一点挖掘,当我调用 docker-compose up 时,我的命名卷没有像我在其他教程中看到的那样被创建。

我做错了什么?

这是我的 yml 文件(如果有帮助,我正在使用 macOS 运行我的项目)

version: "3"
volumes:
  postgres:
    driver: local

services:
  database:
    image: "postgres:latest" # use latest postgres 
    container_name: database
    environment:
      - POSTGRES_USER=REDACTED
      - POSTGRES_PASSWORD=REDACTED
      - POSTGRES_DB=REDACTED
    volumes:
      - postgres:/postgres
    ports:
    - 5432:5432


  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "8000:8000"
    volumes:
      - ./src:/src
      - ./config/nginx:/etc/nginx/conf.d
      - ./src/static:/static 
    depends_on:
      - web

  migrate:
    build: .
    container_name: migrate
    depends_on: 
    - database  
    command: bash -c "python manage.py makemigrations && python manage.py migrate"
    volumes:
      - ./src:/src
  web:
    build: .
    container_name: django
    command: gunicorn Project.wsgi:application --bind 0.0.0.0:8000
    depends_on:
      - migrate
      - database

    volumes:
      - ./src:/src
      - ./src/static:/static 
    expose:
      - "8000"

【问题讨论】:

    标签: python django postgresql docker nginx


    【解决方案1】:

    需要将数据目录挂载到/var/lib/postgresql/data

    volumes:
      - postgres:/var/lib/postgresql/data
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-08
      • 2020-07-10
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多