How do you handle access to the local filesystem data with Podman Desktop on macOS?

This blog post is about handling access to local filesystem data with Podman Desktop on macOS and is related to the blog post CheatSheet: Run a PostgreSQL container with Podman and podman-compose.

There can be a situation in which the basic mapping to local folders does not work correctly with Podman Desktop because of access rights to the filesystem. That is why this blog post describes option first, the “normal” one, mapping an existing local folder as volume to the container, and the second one, creating a local Podman volume and copying data into this Podman volume and accessing the data inside the container.

1. Map local folder as volume

This option is about mapping existing local folder and content on you macOS.

  • Create a folder and a file on your local machine.
mkdir demo_data
cd demo_data
touch demo-data.txt
  • Run a nginx container in a detached mode and map the local drive as volume. (“local Drive:Drive inside the Container“)
podman container rm demo-volume-data
podman run -d --name demo-volume-data -v $(pwd)/demo_data:/tmp docker.io/ngnix:latest /bin/sh -c "while true; do echo hello world; sleep 1; done"
  • Access the running container in a shell
podman exec -it demo-volume-data sh
  • In the container, verify is the data a available in the container
# cd tmp
# ls
demo-data.txt
# cat demo-data.txt

2. Use volumes managed by Podman

If the first option doesn’t work because of access rights on our local machine, check out the following approach. With the created volume by Podman, you can ensure that there will be not problem with access rights to the file system.

  • Create a volume managed by Podman.
podman volume create DEMO_DATA
  • Create an example data file on your local machine.
touch demo-data.txt
  • Start a container and map the create volume.
podman run -d --name demo-volume-data -v DEMO_DATA:/tmp \
                       docker.io/nginx:latest /bin/sh -c "while true; do echo hello world; sleep 1; done"
  • Copy the created file to the create volume with the podman cp command.
podman cp ./demo-data.txt demo-volume-data:/tmp
  • Access the running container in a shell
podman exec -it demo-volume-data sh
  • In the container, verify is the data a available in the container
# cd tmp
# ls
demo-data.txt
# cat demo-data.txt

I hope this was useful to you and let’s see what’s next?

Greetings,

Thomas

#podman, #volume, #mapping, #container, #docker, #mount, #development

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑