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
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']
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.
PostgreSQL by default only allows connections from localhost. You will need to configure it to allow remote connections. Update postgresql.conf
and pg_hba.conf
postgresql.conf
listen_addresses = '*'
pg_hba.conf
host all all 0.0.0.0/0 scram-sha-256
podman run --rm --net=slirp4netns:allow_host_loopback=true -it alpine /bin/sh
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
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
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"]
Top comments (1)
This is a very helpful article for developers using Podman. It provides practical tips for a smoother workflow, especially when dealing with connectivity to host services. Servbay is an excellent tool for this, as it provides a complete, pre-configured local development environment, letting you skip these individual configurations and get straight to building your app.