# How to create Volume in Kubernetes like Volume in Docker Compose?

**URL:** <https://discuss.kubernetes.io/t/how-to-create-volume-in-kubernetes-like-volume-in-docker-compose/26677>\
**Category:** General Discussions\
**Created:** [January 11, 2024, 6:38am UTC](https://discuss.kubernetes.io/t/how-to-create-volume-in-kubernetes-like-volume-in-docker-compose/26677 "2024-01-11T06:38:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaryab\_Ali](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/zaryab_ali/32/14010_2.png) [@Zaryab\_Ali](https://discuss.kubernetes.io/u/Zaryab_Ali)\
**Post date:** [January 11, 2024, 6:38am UTC](https://discuss.kubernetes.io/t/how-to-create-volume-in-kubernetes-like-volume-in-docker-compose/26677/1 "2024-01-11T06:38:24Z")

</div>

I am new to Kubernetes and trying to create Volume in it like we create in Docker Compose.

Docker Compose:

```auto
version: '3'
services:
  my-service:
    container_name: my-container
    image: my-image:0.0.1
    volumes:
      - ./src/main/resources:/src/main/resources
    ports:
      - "8082:8082"

```

I’m creating `/src/main/resources volume` in Docker Container. Now I want to create volume like this in `k8's`. What I’ve tried is:

My Deployment.yaml:

```auto
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment

spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-label
  template:
    metadata:
      name: my-pod
      labels:
        app: my-label
    spec:
      containers:
        - name: my-container
          image: my-image:0.0.1
          ports:
            - containerPort: 8082
          volumeMounts:
            - mountPath: /src/main/resources
              name: my-volume
      volumes:
        - name: my-volume
          hostPath:
            path: /home/my-user/src/main/resources
---
apiVersion: v1
kind: Service
metadata:
  name: my-service

spec:
  type: LoadBalancer
  selector:
    app: my-label
  ports:
    - port: 8082
      targetPort: 8082
      nodePort: 31802

```

Above is successfully creating the volume but it is not pasting the contents of `/home/my-user/src/main/resources` in volume `/src/main/resources`. I’ve checked it using command `kubectl exec -it pod-name -- /bin/sh`.

Guide me how can I create volume in k8’s with the content?
