1

I am working on windows 10 trying to convert my flask app to docker flask app, the problem is it cannot create a container for postgres it shows this error:

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

This is my docker-compose.yml file:

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 Answer 1

2

What this error says is that you do not have the proper directory that you're using as the source for the volume: pgdata which should be located in your C:\Users\User\Desktop\DEV\news folder.

Sign up to request clarification or add additional context in comments.

6 Comments

What if i removed the volume, is it going to work? i mean is that will break the app?
It won't, but the data stored in the database will be lost after your container is removed.
What is the best way to save the data from being removed? is it good to create a docker app on windows or not the best choice ?
The best way is to use a volume, like you have it in the docker-compose file you posted. It's not the best choice, but it should be Ok for getting to know docker, if you don't have any better option (i.e. a Linux box ;))
Yeah, it's already mapped in this line: ' volumes: - ./pgdata:/var/lib/postgresql/data/'. You just need to create the folder.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.