DEV Community

jgngo
jgngo

Posted on • Updated on

Podman Tips

If you are using WSL, you may want to install podman instead of docker. It is a drop-in replacement made by Red Hat. You won't need to do sudo service docker start before running docker commands. To install in WSL, just do the following.

sudo apt install podman
Enter fullscreen mode Exit fullscreen mode

Adding dockerhub registry in the default search

Update the configuration file so it can search the docker.io image registry.

/etc/containers/registries.conf

unqualified-search-registries = ['docker.io']
Enter fullscreen mode Exit fullscreen mode

Access localhost from the container

To allow a running container to access a service running on the host like a database server, a special hostname host.containers.internal is created in the container /etc/hosts that points to the local IP.

podman run --rm --net=slirp4netns:allow_host_loopback=true -it alpine /bin/sh
Enter fullscreen mode Exit fullscreen mode

The parameter --net allows access to the host. If you run podman as a regular user, the default network setting is slirp4netns with the allow_host_loopback set to false. This parameter needs to be set to true to allow slirp4netns to reach the host loopback IP host.containers.internal

https://docs.podman.io/en/latest/markdown/podman-run.1.html

For docker-compose or podman-compose, add the following under the service.

network_mode: slirp4netns:allow_host_loopback=true
Enter fullscreen mode Exit fullscreen mode

Set as default

If there is no existing configuration file in /etc/containers/, create a copy of the default containers.conf so you can edit.

sudo cp /usr/share/containers/containers.conf /etc/cont
ainers/
sudo vi /etc/containers/containers.conf
Enter fullscreen mode Exit fullscreen mode

Uncomment and edit the following entry.

# Default options to pass to the slirp4netns binary.
# For example "allow_host_loopback=true"
#
network_cmd_options = ["allow_host_loopback=true"]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)