Several named volumes have been created in docker-compose. How to create these in Kubernetes?

How to transform the following named volume example defined in docker-compose to kubernetes format

version: "3"
    image: z
      - a:/path/inside/container
    image: c
      - a:/path/inside/container

1 Answer 1


k8s have documentation page about volumes and their types https://kubernetes.io/docs/concepts/storage/volumes/

So in short you need to define spec.volumes and spec.containers[].volumeMounts like:

apiVersion: v1
kind: Pod
  name: test-pd
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    - mountPath: /cache
      name: cache-volume
  - name: cache-volume
    emptyDir: {}
  • is emptyDir: {} required if content from one container has to be shared with another container?
    – 030
    Commented Aug 21, 2017 at 15:37
  • emptyDir is one of the container types. As stated in linked docs "An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node." So this is simple directory on storage assigned to the runner. This can be used to share data however this data should be treated as ephemeral.
    – Hauleth
    Commented Aug 21, 2017 at 15:42
  • I try to share a directory from container x in container y
    – 030
    Commented Aug 21, 2017 at 15:48
  • @030 everything depends on what data you want to share and if that containers run on the same node.
    – Hauleth
    Commented Aug 21, 2017 at 16:03
  • What would be the equivalent of emptyDir, but the data is not ephemeral. I don't want to have to define a hostPath or anything similar- I would like k8s to simply allocate some persistent disk resources for me and mount them onto a container. This is for local dev only - not needed for production. I've read the docs, but nothing seems clear and easy for what is so simple in docker-compose world. Commented Jul 21, 2021 at 17:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.