Docker-compose-无法为服务postgres创建容器

时间:2020-01-11 14:39:43

标签: docker docker-compose

我正在Windows 10上尝试将flask应用程序转换为docker flask应用程序,问题是它无法为postgres创建一个容器,它显示此错误:

Successfully tagged news_web:latest Creating news_postgres_1 ... error ERROR: for news_postgres_1 Cannot create container for service postgres: invalid volume specification: 'C:\Users\User\Desktop\DEV\news\pgdata:/var/lib/postgresql/data/:rw': invalid mount config for type "bind": bind source path does not exist: c:\users\user\desktop\dev\news\pgdata

这是我的docker-compose.yml文件:

version: '3.7'

services:

postgres:
    restart: always
    image: postgres:11.0
    expose:
    - "5432"
    volumes:
    - ./pgdata:/var/lib/postgresql/data/

web:
    restart: always
    build: ./news
    command: ["python", "manage.py", "runserver"]
    volumes:
    - ./news:/usr/src/news/app
    ports:
    - 5000:5000
    env_file:
    - ./news/.env
    depends_on:
    - postgres
    environment:
    - ENV=staging
    - POSTGRES_DB=newsdb
    - POSTGRES_USER=postgres
    - POSTGRES_HOST=postgres
    - POSTGRES_PASSWORD=123123
    - POSTGRES_PORT=5432

1 个答案:

答案 0 :(得分:1)

此错误的意思是您没有正确的目录用作卷的源:pgdata应该位于您的C:\Users\User\Desktop\DEV\news文件夹中。