Kubernetes (in Docker for Windows) Volume Configuration for Postgres

纵饮孤独 提交于 2019-12-04 17:48:39

This is a known issue with Docker image on Windows. Right now it is not possible to correctly mount Windows directories as volumes. You may however try to workaround it by using a persistent Docker volume. For example:

  db:
    image: postgres
    environment:
      - POSTGRES_USER=<user>
      - POSTGRES_PASSWORD=<pass>
      - POSTGRES_DB=<db_name>
    ports:
      - <ports>
    volumes:
      - pgdata:<path>
    networks:
    - <network>

volumes:
  pgdata:

More Information:

Please let me know if that helped.

Have you tried using WSL? My setup for windows is WSL + Ubuntu + Docker for windows and I can mount volumes normally.

I've followed that tutorial to configure all my environment:

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

I found a partial solution to this issue.

Interestingly, if I assign a linux-style path as my host-path (on Windows), then my pgdata-vol persists until Docker Desktop is restarted.

Instead of mounting to a real windows location

  volumes:
  - name: "pgdata-vol"
    hostPath:
      path: /c/temp/vols/pgdata

I use a "linux" location as my Windows hostPath

  volumes:
  - name: "pgdata-vol"
    hostPath:
      path: /tmp/vols/pgdata

Curiously, I cannot actually find this path from Windows. I presume this /tmp is local to my Docker Desktop instance.

This solution does not offer true persistence, but it has helped me to work around a roadblock that was impacting testing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!