6

I have a tomcat + postgres application that I test with docker-compose. I am trying to package the application in a kubernetes config file.

For now, I am running kubernetes (and kubectl) using my Docker Desktop for Windows installation. Eventually, I want to deploy to other environments.

I am currently trying to replicate some of the volume functionality in docker-compose within the following config file.

apiVersion: v1
kind: Pod
metadata:
  name: pg-pod
spec:
  volumes:
  - name: "pgdata-vol"
    #emptyDir: {}
    hostPath:
      path: /c/temp/vols/pgdata
  containers:
  - image: postgres
    name: db
    ports:
    - containerPort: 5432
      name: http
      protocol: TCP
    volumeMounts:
    - mountPath: "/pgdata"
      name: "pgdata-vol"
    env:
    - name: PGDATA
      value: /pgdata

When postgres launches, I get see the following error.

fixing permissions on existing directory /pgdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
2019-07-26 20:43:41.844 UTC [78] FATAL:  data directory "/pgdata" has wrong ownership
2019-07-26 20:43:41.844 UTC [78] HINT:  The server must be started by the user that owns the data directory.
child process exited with exit code 1
initdb: removing contents of data directory "/pgdata"
running bootstrap script ...

I presume that I either need to provide some additional parameters to my volume definition or I need to try a different type of volume config (local vs hostPath).

3 Answers 3

3

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.

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

Comments

2
+50

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.

5 Comments

Thanks. When I run my system with docker-compose, I create a volume as you have described above. I wish I knew of a way to mount a volume created as you describe to kubernetes.
Are you familiar with Persistent Volumes?
I had found that page, but I am unclear how to implement the options in my example. Ideally, I would simply like to replicate the type of volume that docker-compose creates (and persists).
I see your point. I think it would be best if you ask this in a separate question. Would be easier and more transparent for all folks interested.
I have created a new question. Thank you for the suggestion. stackoverflow.com/questions/57378980/…
1

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.