2

I created a PostgreSQL database in Docker container and tried to create a local folder and mount it as a data volume for our running container to store all the database files in a known location as shown below:

docker run -d `
  --name postgres-dev `
  -e POSTGRES_PASSWORD=<my_password>  `
  -v //D/dev/docker/postgresql/data/:/var/lib/postgresql/data `  
  -p 5432:5432 -d postgres

ALthough I created the image and connect it via pgAdmin without any problem, there is no file on D:\dev\docker\postgresql\data location even after creating a table and inserting data into it.

I want to use my local Windows folder D:\dev\docker\postgresql\data as data volume, but I am not sure if I converted the following line of the example that I followed correctly:

from -v ${HOME}/postgres-data/:/var/lib/postgresql/data
to -v //D/dev/docker/postgresql/data/:/var/lib/postgresql/data

I think the example is for Linux, but I have no idea what is the first and second parts before and after ":" Could you please clarify me about these parts and how I should use it properly to use my local Windows folder D:\dev\docker\postgresql\data as data volume?

6
  • @tink Are you sure that you raed the question well? -v ${HOME}/postgres-data/:/var/lib/postgresql/data Commented Apr 23, 2021 at 20:58
  • Yeah, absolutely sure ... I appreciate that the container is Linux; but the problem is most likely on the windows side of things. Commented Apr 23, 2021 at 20:59
  • Not actually, the problem is not creating a file after adding data to db. But if you have time and try it to Linux and then check if you have file in ${HOME}/postgres-data/ location would be also useful. Commented Apr 23, 2021 at 21:04
  • Works for me w/ docker run -d --name postgres-dev -e POSTGRES_PASSWORD=password -v /home/tink/D/dev/docker/postgresql/data/:/var/lib/postgresql/data -p 5433:5433 -d postgres ... had to choose different ports because I run postgres natively. Commented Apr 23, 2021 at 21:58
  • 1
    @Diana Stack Overflow is meant to be a library of questions and answers to be a resource for future readers for years to come. When you ask a question and get answers, you can't edit the question to something completely different. Edits are for small corrections and clarifications. By changing the question you invalidate the existing answers and future readers will not benefit from this post. If you have new follow-up questions, ask them as new and link to this one for context Commented Apr 24, 2021 at 0:03

1 Answer 1

1

Without a windows installation in sight to test this, I expect that your invocation would need to look like this:

docker run -d `
  --name postgres-dev `
  -e POSTGRES_PASSWORD=<my_password>  `
  -v D:\dev\docker\postgresql\data:/var/lib/postgresql/data `  
  -p 5432:5432 -d postgres

That is if windows uses backticks for multiline input ... again, can't verify locally.

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

3 Comments

Thanks a lot. I also tried the same by removing `\` part and It worked. On the other hand, I have some problem for backup data. Could you please have a look at 1 and 2 in my updated question?
Hi @Diana, I appreciate that you're new here at Stack Overflow. But this is not how this site works; you post one question, you -with some luck- get one or more answers that help you with the problem. Then going in and changing the original question to something new or adding another question to it is against both the spirit and the rules of this site. Please post a new question for the new problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.