rootless podman doesn't work on WSL2 after system restart
Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)
/kind bug
Description
If you run a container on WSL2 using podman run -d -p 8080:80 nginx and restart (or sign out from) your windows PC, you get an error message after every podman command, until you delete or restart a couple of times this container.
ERRO[0000] error joining network namespace for container 88a8d5c7115598aeaa31fcd1cee8c084fee3ab2577b4f61dc317053d7da032f9: error retrieving network namespace at /tmp/podman-run-1000/netns/cni-f73b0b0b-155d-3c43-30b2-278280c003f1: unknown FS magic on "/tmp/podman-run-1000/netns/cni-f73b0b0b-155d-3c43-30b2-278280c003f1": ef53
Error: error joining network namespace of container 88a8d5c7115598aeaa31fcd1cee8c084fee3ab2577b4f61dc317053d7da032f9: error retrieving network namespace at /tmp/podman-run-1000/netns/cni-f73b0b0b-155d-3c43-30b2-278280c003f1: unknown FS magic on "/tmp/podman-run-1000/netns/cni-f73b0b0b-155d-3c43-30b2-278280c003f1": ef53
The same happens if you run a pod using the command podman play kube filename.yaml. In this case you need to remove the pod or restart it a couple of times to get rid of the error.
Steps to reproduce the issue:
-
Install WSL2 and podman inside WSL2 on Windows PC
-
Run
podman run -d -p 8080:80 nginx -
Sign out from Windows PC (or restart it)
-
Run
podman ps
Additional information you deem important (e.g. issue happens only occasionally):
There is a workaround: Originally posted by @alexcern in https://github.com/containers/podman/issues/6800#issuecomment-943288170
My understanding is there is no systemd/init.d at all; it seems we can run things at startup via the Windows scheduler (example) but that's not very convenient.
In my case I made do with assuming that
/proc/1being more recent than the temp folder indicated a reboot took place. I added this to my.bashrc:function refresh_rootless_podman_after_reboot { local libpod_tmp="/tmp/run-$(id -u)/libpod/tmp" if [ /proc/1 -nt "${libpod_tmp}" ]; then rm -rf "${libpod_tmp}" fi } refresh_rootless_podman_after_rebootBut a simpler solution could be to include the boot ID in the temp path so we always get a fresh folder after reboot, e.g
export XDG_RUNTIME_DIR="/tmp/run-$(id -u)/$(cat /proc/sys/kernel/random/boot_id)"
In our project we use podman play kube filename.yaml to start the pod, so this workaround works only after adding podman pod restart -all command 3 times after the function (the first 2 restarts return an error)
function refresh_rootless_podman_after_reboot {
local libpod_tmp="/tmp/run-$(id -u)/libpod/tmp"
if [ /proc/1 -nt "${libpod_tmp}" ]; then
rm -rf "${libpod_tmp}"
fi
}
refresh_rootless_podman_after_reboot
podman pod restart --all
podman pod restart --all
podman pod restart --all
Output of podman version:
Version: 3.3.1
API Version: 3.3.1
Go Version: go1.16.6
Built: Thu Jan 1 01:00:00 1970
OS/Arch: linux/amd64
Additional environment details (AWS, VirtualBox, physical, etc.): Ubuntu 20.04.3 LTS on WSL2 on Windows 11
Tried also with Ubuntu 18.04 on WSL, with Debian on WSL and with Podman 3.0.1
I recommend to mount a tmpfs on /tmp. Having the tmp files available after a reboot results in all sort of bugs. e.g. podman ps will show wrong information because it thinks your containers are still running.
@mheon Any other ideas?
At some point during system restart, /tmp/podman-run-1000/alive has to be removed, so we detect the restart. Recommended way of doing that is a tmpfs, as @Luap99 said, but a script doing it (so long as that script ran only once, and only ran immediately after a restart) would also work.
For now, you can manually remove the file, which will cause a restart to be detected and should make Podman fully usable again.
Don't see how Podman can fix this issue. Closing.
@Luap99 What do you mean with mount a tmpfs on /tmp ?
In my case I tired with podman run -d --name nginx -p 8080:80 nginx then wsl --shutdown
After that podman ps -a show the same message but the container is not running anyway.
I can do a podman stop nginx. Then podman ps -a works back normally but the container cannot be started again.
The only solution is to remove it an recreate.
The /tmp files should be on a temporary filesystem. So you either remove the /tmp/... files after each boot before you run any podman commands or the easier solution is to mount a temporary filesystem which only exists in ram so it is automatically deleted for each boot. You can run this command to do it: mount -t tmpfs none /tmp, on normal linux distros you can set this in /etc/fstab so that this mountpoint is always created on boot, I have no idea if this works on wsl.
So I removed the /tmp folder.
I edited the fstab to mount tmpfs on /tmp.
I seems working. I created a file in /tmp. After reboot /tmp is empty.
I tired again podman run -d --name nginx -p 8080:80 nginx
Reboot.
podman ps -a ... is working without any message !
Of course the container is not started but I can do it with podman start nginx.
It is full working.
Many thanks.
Had the same issue. Implemented the tmpfs mount @Luap99 posted
Here is how I set fstab to mount tmpfs, it works. I post it here for others who don't konw how to configure fstab.
echo "none /tmp tmpfs defaults 0 0" | sudo tee -a /etc/fstab
create /tmp folder if not exist
sudo mkdir /tmp
sudo chmod 1777 /tmp
I am running podman in WSL2 and I got this error after I've restarted the host. The solution for me was to run in powershell on the host the command: podman machine start
Maybe it will help someone that runs into this for the same reason as me.
Don't see how Podman can fix this issue. Closing.
May be not writing persistent data to a temporary folder ? Why such info are not written into ~/.local/share ?