Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

A rootless Podman container cannot reach a service running on the host

Your error

nc: connect to 192.168.1.100 port 443 (tcp) failed: Connection refused1 more line it can show

Fix it fast

Most common cause, 1 of 4

The app dials the host's LAN address, which pasta also gave to the container

Use the name host.containers.internal, or map your own name with --add-host name:host-gateway.

Fix
podman run --rm alpine wget -qO- http://host.containers.internal:8080/
# or a name of your choice
podman run --rm --add-host api.local:host-gateway alpine wget -qO- http://api.local:8080/
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Connection refused from a rootless Podman container to a host service usually means the wrong target for pasta networking. The host IP is copied into the container, the gateway is unmapped, and host.containers.internal (or host-gateway) reaches the host's global address, not 127.0.0.1. Use that name, bind the service beyond loopback, or forward with pasta -T. Applies to Podman 6.x.

  • Applies to Podman 6.2, rootless, default pasta network, pasta from the passt project
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Look at the hosts file and the routes a fresh container gets. The host.containers.internal line (or its absence), the copied addresses and the gateway together point to one of the causes below.

Run this first
podman run --rm alpine sh -c 'cat /etc/hosts; ip -4 addr; ip route'

Then find the line you see in this list and open its fix:

  1. 1The app dials the host's LAN address, which pasta also gave to the containerThe address the app connects to appears in ip -4 addr inside the container
  2. 2The host service only listens on 127.0.0.1ss on the host shows 127.0.0.1:8080 as the local address instead of 0.0.0.0:8080 or the LAN address
  3. 3The app uses the default gateway IP, a habit from Docker's bridgeThe configured host address equals the via address printed by ip route in the container
  4. 4host.containers.internal never made it into /etc/hostsgrep finds no host.containers.internal line and the name does not resolve

What does the error look like?

  • nc: connect to 192.168.1.100 port 443 (tcp) failed: Connection refused
  • Connecting to 10.1.26.100:8091... failed: Connection refused.

Cause 1 of 4

The app dials the host's LAN address, which pasta also gave to the container

You seeThe address the app connects to appears in ip -4 addr inside the container

Check

Refused connections to the host's own IP are expected with pasta, the default for rootless containers, because it copies the host's addresses and routes into the container. The packet never leaves the container's namespace, and nothing there listens on that port.

Check
podman run --rm alpine ip -4 addr

Fix

Use the name host.containers.internal, or map your own name with --add-host name:host-gateway. Podman passes --map-guest-addr 169.254.1.2 to pasta by default, and that address is translated to the host.

Fix
podman run --rm alpine wget -qO- http://host.containers.internal:8080/
# or a name of your choice
podman run --rm --add-host api.local:host-gateway alpine wget -qO- http://api.local:8080/

Verify

The hosts file lists host.containers.internal with 169.254.1.2 and the request returns the service's reply.

Verify
podman run --rm alpine grep host.containers.internal /etc/hosts

Confirmed by docs.podman.io

Did this fix it?

Cause 2 of 4

The host service only listens on 127.0.0.1

You seess on the host shows 127.0.0.1:8080 as the local address instead of 0.0.0.0:8080 or the LAN address

Check

The guest address that pasta maps leads to the host's global address. A service bound to loopback is not listening there, which is why it answers curl localhost on the host and refuses the container.

Check
ss -ltn

Fix

Make the service listen on the host's LAN address or on all addresses, and limit access with its own settings or the firewall. To keep it on loopback, let pasta forward that port from the container's loopback to the host's loopback with -T, and point the app at 127.0.0.1.

Fix
# keep the host service on 127.0.0.1:8080
podman run --rm --network pasta:-T,8080 alpine wget -qO- http://127.0.0.1:8080/

Verify

ss shows the new bind address, or the -T run gets an answer from 127.0.0.1:8080 inside the container.

Verify
ss -ltn | grep 8080

Confirmed by passt.top

Did this fix it?

Cause 3 of 4

The app uses the default gateway IP, a habit from Docker's bridge

You seeThe configured host address equals the via address printed by ip route in the container

Check

Podman starts pasta with --no-map-gw unless told otherwise, so traffic to the gateway address is not redirected to the host. The design blocks direct host access through the gateway.

Check
podman run --rm alpine ip route

Fix

Switch the setting to host.containers.internal. When a tool can only take the gateway IP, add --map-gw to the pasta options of that container.

Fix
podman run --rm --network pasta:--map-gw alpine wget -qO- http://<gateway-ip>:8080/

Verify

The request through the name, or through the gateway with --map-gw, returns the service's reply.

Verify
podman run --rm alpine wget -qO- http://host.containers.internal:8080/

Confirmed by docs.podman.io

Did this fix it?

Cause 4 of 4

host.containers.internal never made it into /etc/hosts

You seegrep finds no host.containers.internal line and the name does not resolve

Check

Podman adds the name only when it can work out an address for the host, and skips it without a message when it cannot. --no-hosts, no_hosts = true, or host_containers_internal_ip = "none" in containers.conf also leave it out.

Check
grep -E 'no_hosts|host_containers_internal_ip' ~/.config/containers/containers.conf /etc/containers/containers.conf 2>/dev/null

Fix

Remove --no-hosts and no_hosts = true. If automatic detection still fails, set host_containers_internal_ip in the containers table; with rootless pasta the default mapped address is 169.254.1.2.

Fix
# ~/.config/containers/containers.conf
[containers]
host_containers_internal_ip = "169.254.1.2"

Verify

A new container shows the name in its hosts file, and --add-host with host-gateway no longer fails.

Verify
podman run --rm alpine grep host.containers.internal /etc/hosts

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Put host.containers.internal, never a literal host IP, in the env files and compose files your containers read.
  • Decide per host service whether containers may reach it, and give those services a non-loopback bind address on purpose.
  • Keep pasta_options in the network table of containers.conf under version control when you rely on --map-gw or forwarded ports.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.