SLAF
SLAF

Reputation: 51

Mount Docker volume on Windows host with Linux containers in docker-compose.yml

I just started using Docker and the Docker Compose feature to set up my Web App services. I'm running Docker on a Windows Host using Linux Containers. I got this named volume called db_volume that I use for my PostgreSQL service.

services:
  postgres_image:
    image: postgres:latest
    ports:
      - "5432"
    restart: always
    volumes:
      - db_volume:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
      POSTGRES_DB: "db1"
volumes:
  db_volume:

When I use docker volume inspect on this named volume, I can see that the Mountpoint path is a Linux path.

"Mountpoint": "/var/lib/docker/volumes/dockercompose18019271739475279775_db_volume/_data"

I was wondering if there is any way to convert this path to a Windows one so that I can import these data in my pgadmin databases.

I already set the COMPOSE_CONVERT_WINDOWS_PATHS=1 in my .env file, but it didn't seem to work.

I also shared both my C and D drive in the Docker settings.

Upvotes: 4

Views: 6958

Answers (2)

Danil
Danil

Reputation: 895

you'll need something like this:

volumes: 
      - //d/pgdata/:/var/lib/postgresql/data

for Windows filesystem and from c# you'll request "/var/lib/postgresql/data" path

Upvotes: 0

Steve Boyd
Steve Boyd

Reputation: 1357

There is no way to convert this to a windows path, because in this scenario it is not on the windows filesystem. The storage you have allocated is on the MobyLinux VM which is created as part of your windows install. If you want to have the storage appear as part of your local windows filesystem then you need to do something like this which maps the data directory to the host filesystem:

version: '3'

services:
  postgres:
    container_name: pg
    image: postgres:latest
    ports:
      - "5432"
    restart: always
    volumes:
      - d:/pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
      POSTGRES_DB: "db1"

You should note that on windows you will need expose your drive via the "Shared Drives" settings in the Docker settings.

Upvotes: 1

Related Questions