Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docker] Volumes within db causes issue's on Windows #1

Open
thebspin opened this issue Apr 9, 2020 · 12 comments
Open

[Docker] Volumes within db causes issue's on Windows #1

thebspin opened this issue Apr 9, 2020 · 12 comments

Comments

@thebspin
Copy link

thebspin commented Apr 9, 2020

So on line 7 from the docker-compose file it says: - ./docker-data/db-data:/var/lib/postgresql/data
This works fine on my Mac but does not on Windows.
It complains about chmod (probabaly because docker is a different user?)
It is not something new perse (see docker-library/postgres#435) and there are many other issue's on git about it.

Being new myself to Docker i tried some stuff but i could not figure it out.
I hope you could tell me how to achieve the same on Windows so i could follow on my Desktop (and not laptop)

@w3cj
Copy link
Member

w3cj commented Apr 19, 2020

Maybe something from this thread can help? docker/compose#4303

@thebspin
Copy link
Author

Maybe something from this thread can help? docker/compose#4303

I've read multile issue's including that one.
But when using that doesn't it break when using a different system?
Correct me if i'm wrong but isn't the idea of having a docker-compose file that it's also system independent?

@jessikuh
Copy link

I'm not sure if you already solved the issue, but I am able to get docker-compose to execute correctly on Windows 10 by removing the '.' from the volume. See below.

    volumes:
      - /docker-data/db-data:/var/lib/postgresql/data

I read elsewhere that some people had to manually create the volume on Windows 10, as well, but this did the trick for me.

@thebspin
Copy link
Author

@jessikuh

Hmm i'm sure i would have tried it but yes indeed.. it spins up without any issues!
Would you also happen to know where exactly the docker-data is being saved on windows now?

@jessikuh
Copy link

With my little knowledge, I think they're stored in the VM. It does look like you can copy volumes between your system and the container as documented here. I hope that helps. :/

@thebspin
Copy link
Author

Yeah that's what i was afraid off.. the idea of the volumes in CJ's example is that it's stored external i believe, so you don't lose the data. After i add some data, turn off the container and spin it up again i lost all my data now :(

@jessikuh
Copy link

I haven't experienced any data loss after stopping my container, only after shutting Docker off and on. If you seed your data with knex, you won't lose it since it'll be stored in the seed file. Otherwise, you could install Postgres locally. :)

@Sageza-84
Copy link

Sageza-84 commented May 4, 2020

` services:

db:
image: postgres
restart: always
volumes:
- postgres:/var/lib/postgresql/data
- ./docker-data/db-data:/etc/postgresql/
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- 5432:5432

adminer:
depends_on:
- db
image: adminer
restart: always
ports:
- 8080:8080
volumes:
postgres:`

works for me on win10 pro

@thebspin
Copy link
Author

works for me on win10 pro

Like this?

version: "3.1"
services:
  db:
    image: postgres
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data
      - ./docker-data/db-data:/etc/postgresql/
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_DB: ${POSTGRES_DB}
    ports:
      - 5432:5432
  adminer:
    depends_on:
      - db
    image: adminer
    restart: always
    ports:
      - 8090:8080
volumes:
  postgres:

@thebspin
Copy link
Author

So while the above does work on windows, it gives me issue's again on my Macbook. I have to prefix the postgres volumes onder db with /. but as you might have guessed.. that breaks it again on windows :)

Is there anyway to get something working multi platform?

@datocrats-org
Copy link

datocrats-org commented May 28, 2020

Does ownership add to this problem? What do you see when you do $ ls -l on the mounted volume within your container and the equivalent in windows?

Ownership of the ./ directory reference in windows should automatically map to the user you are logged in as and running docker-compose with. It may help to be more explicit, though the ownership may not pass through. Docker says docker for windows is for development only, granted, because their volume drivers are only supported on linux. The microsoft workaround is to take ownership using a bit awkward approach: https://docs.microsoft.com/en-us/archive/blogs/stevelasker/configuring-docker-for-windows-volumes

@thebspin
Copy link
Author

How do i do $ ls -l inside a mounted volume?

So today i update my windows to the latest update that includes wsl2.
Using docker for windows with wsl2 also fixed my issue since it is now linux based i suppose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants