OpenShift - Mount an empty directory in a container using the oc set volume command

by
Jeremy Canfield |
Updated: February 20 2025
| OpenShift articles
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
Let's say you have a deployment named "my-deployment".
~]# oc get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
my-deployment 1/1 1 1 8d
The oc set volume command can be used to mount an empty directory in the container.
~]$ oc set volume deployment my-deployment --add --type emptyDir --mount-path /var/empty
info: Generated volume name: volume-879rj
deployment.apps/my-deployment volume updated
A new pod should immediately be created and the oc describe pod command can be used to see that the pod is now has the "foo" and "bar" keys.
~]$ oc describe pod my-pod-65rbl
Volumes:
volume-879rj:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
SizeLimit: <unset>
The oc exec and df command can be used to see that the empty directory has been mounted in the container.
~]$ oc exec pod/my-pod -- df
Filesystem 1K-blocks Used Available Use% Mounted on
overlay 125277164 47124096 78153068 38% /
tmpfs 65536 0 65536 0% /dev
tmpfs 12333448 0 12333448 0% /sys/fs/cgroup
shm 65536 0 65536 0% /dev/shm
tmpfs 12333448 70460 12262988 1% /etc/hostname
/dev/mapper/coreos-luks-root-nocrypt 125277164 47124096 78153068 38% /var/empty
tmpfs 12333448 32 12333416 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs 12333448 0 12333448 0% /proc/acpi
tmpfs 12333448 0 12333448 0% /proc/scsi
tmpfs 12333448 0 12333448 0% /sys/firmware
Did you find this article helpful?
If so, consider buying me a coffee over at