-
Notifications
You must be signed in to change notification settings - Fork 290
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
Mounting data volume for Postgres in docker for Windows doesn't work #445
Comments
I think this is a duplicate of #39 For the time being, this won't work. You should either just use in-container storage or use a volume not mounted from your Windows host. Is there a particular reason you want the data to be on the windows host? |
Tried it with this approach: https://forums.docker.com/t/trying-to-get-postgres-to-work-on-persistent-windows-mount-two-issues/12456/5 command line
docker-compose.yml...
...
|
also affected |
Same here. Ah come on, so you need a specific reason why to support a core Docker functionality? Like, well, I expect it to work with storing the data in a volume instead of being stuck in some random volume that I can't move to another server due to cryptic file paths and so I want my docker data + config to stay in the same folder so it's easy for me to backup, like a good DevOp would do? Holy Christ. If MariaDB can do it, why Postgre can't? I don't want my data to be wiped out when I turn off the container. +1 to this, it needs to be fixed. |
Same issue, luckily I'm just picking my database now. |
Same issue. Apparently no solutions for 1 year now... |
Docker & Production ready. That's two separate products. |
Same problem. |
I've solved the problem by creating a new volume like that : And then you link it like that :
|
flavienbwk: Your solution works. :) Thank you. |
Perfect! |
This work but this is bad solution, global docker volumes creating inside of docker VM on Windows and MAC, what make pack of problems, such as no option to modify or inspect data of volumes.
|
@Cugap Maybe a bad solution but there's no proposed solution by the Docker team, that has closed the issue whereas it is not solved. Maybe they should do something ? |
Please consider reopening! |
@friism pls reopen cause problem is still active, and maintaining of containerized DB is a real problem. |
ping @carlfischer1 |
ping @gtardif |
this is really frustrating. Please reopen this issue. |
@hasnatbabur Yes, I tried with ${PWD}/data:/var/lib/postgresql . Unfortunately, it does not copy the contents of the data folder. Every time I made a change to my yml file, I made sure to delete all generated volumes and instances before re-composing. I even tried using pgdata environment variable to change the location of the data, but that did not work either. Are you using Docker toolbox or Docker desktop? |
@watchdogoblivion I am using Laradock and this is my final docker-compose.yml file for postgres: |
Why this issue is still closed? |
#445 (comment) and number one reason: Postgres wants its data with special permissions Windows does not support. Use a volume or Linux or not Postgres. There is nothing feasible Docker can do to fix it. |
I use a volume, but i must use external one to make it work right. For example:
in my docker-compose file. If I make it regular the database stops immediately. |
I think there's a post on this thread showing how to set ntfs permissions
to make this work. If you can do it by hand then IMHO docker should
provide an easier way to do it.
…On Thu, Nov 21, 2019, 10:07 AM Sandro ***@***.***> wrote:
Why this issue is still closed?
#445 (comment)
<#445 (comment)> and
number one reason: Postgres wants its data with special permissions Windows
does not support. Use a volume or Linux or not Postgres. There is nothing
feasible Docker can do to fix it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#445?email_source=notifications&email_token=AC5R66EWENY4DF2MRXKCLRDQU2PZLA5CNFSM4C6F2NK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE2RBUY#issuecomment-557125843>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5R66EOTVNAJ2DOZIYNPRTQU2PZLANCNFSM4C6F2NKQ>
.
|
Attempt to add volume mount to persist PSQL data (and potentially access from local DB instance). But alas, this does not seem to be supported the way I want: docker/for-win#445
I landed into this thread as literally single search result which really relevant to me.
and mount this with
to use the
And what? |
If I need local storage on the machine? How to be? |
Met the same issue with Windows 10, Docker for Desktop. Finally found the workaround, verified.
For example:
|
But when |
What I am seeking is the ability to use the same database in the container
and outside it -- though not simultaneously, which would only lead to data
corruption. e.g.
1. From Windows, start up a local (not in a container or vm) instance of
PostgreSQL. Create a database and put stuff in it
2. Stop the local instance
3. fire up a PostgresSQL container, and tell it to use the *same data base
files I* just created and filled on Windows.
4. Do some more stuff on the containerized PostgresQL. Add more data etc.
5. Shutdown the container
6. Fire up the local instance again
7. See that the data is a combination of things from step 2 and step 4.
…On Wed, Mar 18, 2020 at 1:50 PM strarsis ***@***.***> wrote:
But when PGDATA points to a directory inside the docker postgres
container, not mounted on host,
all data is lost after resetting the docker postgres container. This makes
the whole thing pointless.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#445 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5R66CQI4AST45JUCWE76DRIECWJANCNFSM4C6F2NKQ>
.
--
Gerald Britton, MCSE-DP, MVP
LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton
|
So now I have the Postgres Server Windows edition directly running and connect the containers to the Docker Host ( Note: Don't confuse this with the domain |
A partial workaround can be done by using Postgres tablespaces to store the database object files on the windows host system. It is not a perfect solution, but at least if you have a large database, it can be stored outside the Linux VM.
This sets the default data storage to a (persistent) directory on the Linux VM (
Go ahead and create tables and data in |
@mldisibio: Your approach seems to fix the whole issue. Why is this only "partial" data? Isn't the data directory in Postgres the same as the "tablespace" data? Let's say the postgres container is completely removed, can the database still be used with another postgres container? |
@strarsis I called this a 'partial' solution because I don't know enough about PostgreSQL internals to understand well what this gets us beyond table storage outside of the LinuxVM and onto the Windows host file system. Have a look at Database File Layout in the PostgreSQL documention and its clear that the most critical configuration and control files are stored in So my gut response to your question is No, I don't think the data in the windows host filesystem is useable if the PGDATA linux directory goes away. That said, PGDATA is at least not on the Postgres container (physically) but rather is on the LinuxVM, so yes, it's still okay if the Postgre container is completely removed. In fact, the Before I make any further comments, let me make it abundantly clear. The only correct way to both make data portable and to recover from loss, is through proper backup and restore operations. So I have worked with Sql Server for 18 years and am relatively new to Postgre. Given that this issue is opened by users of Docker for Windows using a linux container with Postgres, I bet most of the db developers are looking for the familiar experience with Sql Server that is much more file oriented. You specify where you want your database file ( I am fairly certain none of this is being achieved with the Interestingly enough however, knowing that we can mount a windows directory to the PostgreSQL container even though it is not the core |
Where? |
I was able to solve this issue by configuring my Docker Desktop for Windows to use the new WSL 2 backend (instead of Hyper-V).
Also note this docker compose needs to be run from PowerShell or CMD and not from your WSL linux console. The volume definition "d:/postgis/data:/var/lib/postgresql" does not work in linux. |
Nice, I ended up just running the containers from the ubuntu (WSL) console storing the code/data on the WSL share which I mapped as a network drive (Z:) seems faster and iNotify works now :) |
@LiamKarlMitchell: So you store the postgres datafiles on a network drive and mounted that network drive into the postgres container, and this fixes the permissions issue? |
I followed the steps to use the WSL 2 backend for Docker Desktop on Windows and was able to resolve this issue. I installed Ubuntu from the Microsoft Store to use as my distro. |
Something like that? So on windows version: "3.7"
services:
db:
image: postgres:9.5.21-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: myproject
volumes:
- db-data:/var/lib/postgresql/data
- ./pgdata/dump.sql:/docker-entrypoint-initdb.d/dump.sql
# ..... near bottom of the file ....
volumes:
db-data: When I want to run the project I need to first goto Ubuntu installed from Microsoft Store. |
Closed issues are locked after 30 days of inactivity. If you have found a problem that seems similar to this, please open a new issue. Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. |
Expected behavior
Postgres should start and mount the correct windows directory as a data volume
Actual behavior
Information
docker-compose.yml file :
Note : Substituted
<user>
with my userdocker-compose.env file
Steps to reproduce the behavior
Similar issue was already reported on moby/moby#25908 but was redirected here to be checked/opened on https://github.com/docker/for-win/issues
I have searched for this issue in Open and Closed issues list, but couldn't find any.
I'm using
The text was updated successfully, but these errors were encountered: