podman: Podman Init wont Resolve DNS Windows WSL

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Podman machine unable to resolve DNS

Steps to reproduce the issue:

  1. podman machine init

Describe the results you received:

When trying to install packages for Fedora 35 the WSL VM is unable to resolve the repo mirrors

Errors during downloading metadata for repository 'fedora':
  - Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-35&arch=x86_64 [Could not resolve host: mirrors.fedoraproject.org]
Error: Failed to download metadata for repo 'fedora': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-35&arch=x86_64 [Could not resolve host: mirrors.fedoraproject.org]
Error: package upgrade on guest OS failed: exit status 1

Describe the results you expected:

I would expect it to use the hosts DNS server settings to resolve

Additional information you deem important (e.g. issue happens only occasionally):

This might be related to an issue with WSL https://github.com/microsoft/WSL/issues/3438 It is important not for me to be able to access the Internet on any WSL instance I always need to config the resolve.conf to have the appropriate DNS nameservers

Output of podman version:

Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman socket: Get "http://d/v4.1.0/libpod/_ping": dial unix /wsl$/Fedora34/run/podman/podman.sock: connect: A socket operation encountered a dead network.

Output of podman info --debug:

Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman socket: Get "http://d/v4.1.0/libpod/_ping": dial unix /wsl$/Fedora34/run/podman/podman.sock: connect: A socket operation encountered a dead network.
P

Package info (e.g. output of rpm -q podman or apt list podman):

N/A

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

Yes

Additional environment details (AWS, VirtualBox, physical, etc.): The ability to update the resolve conf as part of the init would be appreciated or to run init wait for it to fail fix the VM manually and then continue the setup

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 33 (7 by maintainers)

Most upvoted comments

Here’s my workaround, it requires a separate WSL instance (I used ubuntu) and you’ll need to run the commands as root so the owner bits are properly saved.

  1. Download the fedora image as mentioned in @JerryMWeeks post - https://github.com/fedora-cloud/docker-brew-fedora/blob/35/x86_64/fedora-35-x86_64.tar.xz
  2. Open WSL instance as root and cd to directory where you downloaded the fedora tar file
  3. mkdir /fed && tar xfJ fedora-35-x86_64.tar.xz -C /fed - Extract the tar
  4. cd /fed
  5. echo -e "nameserver 1.1.1.1\n" >./etc/resolv.conf - Use cloudflare DNS (replace IP as required)
  6. echo -e "[network]\ngenerateResolvConf = false\n" >./etc/wsl.conf - Tell WSL not to mess with our DNS
  7. tar cfJ /fedora.tar.xz * - Rebuild the tar
  8. mv /fedora.tar.xz <windows_folder> - Put it where podman can get at it
  9. (In powershell/cmd) podman machine init --image-path fedora.tar.xz - init podman

And here’s a scripty version of it. May contain typos.

#!/bin/bash
# In powershell: cd to where TAR_IN is located, run 'wsl -d <distro> -u root --', then run this script
TAR_IN="fedora-35-x86_64.tar.xz"
TAR_OUT="fedora.tar.xz"
mkdir /fed && tar xfJ "$TAR_IN" -C /fed
pushd /fed
echo -e "nameserver 1.1.1.1\n" >./etc/resolv.conf
echo -e "[network]\ngenerateResolvConf = false\n" >./etc/wsl.conf
tar cvfJ "/$TAR_OUT" *
popd
mv "/$TAR_OUT" .

I found an alternative way - for those urgently needing to get Podman to run.

  1. Run podman machine init - let it run until it fails
  2. Run wsl --shutdown (to make sure the failed podman install has stopped)
  3. Go to Azure or AWS, spin up a VM - Win 10 or whatever your os is. (Azure offers a free trial - so you can do this without cost!) Update: Make sure the login on the VM is the same as your login on local machine (the ssh cert path inside the Podman default machine will fail otherwise)
  4. Login to your new VM
  5. Run PowerShell admin
  6. Run WSL --install (the latest way to install wsl)
  7. Reboot to complete the install - on reboot Ubuntu should complete loading, you might need to wait for that to complete
  8. Download and install podman
  9. run podman machine init
  10. allow setup to complete
  11. run podman machine start
  12. observe if start is successful
  13. if yes, run podman machine stop
  14. 7zip up c:\users<remote login name>.local and .config and .ssh (you might need to enable viewing hidden / system files)
  15. Copy the .7z file (or zip if you used zip)
  16. Paste in your local laptop at a suitable location (c:\temp\podman) And unzip.
  17. Copy containers.conf from the VM c:\users<your remote login>\AppData\roaming\containers
  18. paste that in the same suitable location (c:\temp\podman)
  19. Edit the json file podman-machine-default.json in the unzipped .config\containers\podman\machine\wsl updating the path in 3 places to match your local machine login / user name (unless you set up your VM in Azure to have the same login name)
  20. e.g. line 9: "C:\Users\remote-vm-login-name\.ssh\podman-machine-default becomes "C:\Users\local-login-name\.ssh\podman-machine-default
  21. Copy .config to c:\users<your local login> replacing / overwriting existing files
  22. Copy .local to c:\users<your local login> replacing / overwriting existing files
  23. Copy .ssh contents to c:\users<your local login>.ssh
  24. copy the edited / saved podman-machine-default.json to c:\users<your local login>\AppData\roaming\containers replacing / overwriting existing file
  25. run podman machine stop (shouldn’t do anything - might error)
  26. run podman machine start

and if you get as lucky as me …

podman machine start
Starting machine "podman-machine-default"

This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:

       podman machine set --rootful

API forwarding for Docker API clients is not available due to the following startup failures.
       CreateFile \\.\pipe\docker_engine: All pipe instances are busy.

Podman clients are still able to connect.
Machine "podman-machine-default" started successfully

Now to get on with the next step 😉

This should in principle always work as the podman “disk” is a vhd and the container concept is portable - but I am not responsible if you break something!

and more Now to find if it works! phew. which it doesn’t where is this file? podman machine start Starting machine "podman-machine-default" /bin/bash: line 1: /root/bootstrap: No such file or directory Error: WSL bootstrap script failed: exit status 127

Podman machine does a number of customization steps, so thats why you are receiving this error. Until we have a simpler override mechanism, what might work as a temporary hack, is you could modify the rootfs that we start from:

https://github.com/fedora-cloud/docker-brew-fedora/blob/35/x86_64/fedora-35-x86_64.tar.xz

If you add your custom resolv.conf and a /etc/wsl.conf to the tarball with

[network]
generateResolvConf = false

then you pass that the new tar.xz to

podman machine init --image-path custom.tar.xz

I’m not completely sure if those files will survive, but worth a try.