I'm trying to use Podman for local development. My idea is to use a local folder and sync it with the container where I'll be running my application.
I found that the -v
option that I would use if I was working with Docker works with the server machine, as it says in the documentation -v Bind mount a volume into the container. Volume src will be on the server machine, not the client
. Because of that, when I use that option the folder is not mounted and I can't find it when I access it using podman exec -it application bash
Is there a way I can sort this out? I want to something equivalent to:
docker run -v localFolder:/remoteFolder application
where localFolder
is a path in my local machine, that will be mapped on remoteFolder
on the container
podman attach attaches to a running container using the container's name or ID, to either view its ongoing output or to control it interactively. The container can be detached from (and leave it running) using a configurable key sequence. The default sequence is ctrl-p,ctrl-q .
A volume is a storage device cretaed and managed by Podman. Volumes are created directly using the podman volume command or during container creation. Create a volume using podman volume. podman volume create my_vol
The mount point will be /var/vmhost. While the folder name can be changed, it should remain in /var as many other locations in the Podman VM are restricted or reset to default upon reboot. In any case, the file names must match the mount point. Create a file /etc/systemd/system/run-vmhost.automount with a mode of 0644.
Determine which user account is running the process within your container. Enter Podman’s user namespace, and grant this user permissions to write to your directory. Mount the volume when you run the container, add the proper SELinux label to allow the container user to write. First you need to know which UID the container is running as.
podman ps -a shows the container is removed, while podman volume ls shows the volume remains. Mount the existing volume to a new container. --mount: takes the following key-value pairs when mounting an existing volume. The container mount point /data2 shows that the new container mount point does not need to match the original mount point.
podman machine stop podman-machine-default
podman machine rm podman-machine-default
podman machine init -v $HOME:$HOME
podman machine start
podman run -ti --rm -v $HOME:$HOME busybox
You need to make sure to mount volume first to podman machine (in the podman machine init
command).
Let’s say, we’re interested in:
Let’s create the podman machine using:
podman machine init --cpus=4 --disk-size=60 --memory=6096 -v $HOME:$HOME
and start it afterwads:
podman machine start
To see if it runs, let’s use:
podman machine ls
Let’s first run sample (ubuntu) container without mount and see what is present in /opt
dir:
podman run ubuntu ls /opt
No output indicates, that /opt
dir is empty in the container.
Now let’s try with volume mount option:
mkdir test-dir
touch test-dir/test-file.txt
podman run -v ./test-dir:/opt ubuntu ls /opt
test-file.txt
We see that mounted dir with it’s content is accessible in container now!
(Content extracted from: https://medium.com/@butkovic/favoring-podman-over-docker-desktop-33368e031ba0)
Iterating on @zhigang's answer:
podman machine stop podman-machine-default || true
podman machine rm podman-machine-default --force || true
podman machine init -v "$(pwd):$(pwd)"
podman machine start
Now docker-compose / podman-compose just work with their config
version: '3.9' # needed for PyCharm to work
services:
app:
image: python:alpine
working_dir: /app/
volumes: [.:/app/]
$ podman-compose run --rm app venv/bin/python main.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With