Containers

How to mount a directory from the host to a container?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

CONTAINER_BINARY=podman
mkdir /tmp/dir_on_the_host

$CONTAINER_BINARY run -v /tmp/dir_on_the_host:/tmp/dir_on_the_container IMAGE_NAME

In some systems you'll have also to adjust security on the host itself:

podman unshare chown -R UID:GUID /tmp/dir_on_the_host
sudo semanage fcontext -a -t container_file_t '/tmp/dir_on_the_host(/.*)?'
sudo restorecon -Rv /tmp/dir_on_the_host