Search code examples
windowspostgresqldockercontainers

Docker volume is still empty even inserting data to PostgreSQL database


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?


Solution

  • 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.