Allow Podman containers to resolve each other by container name on an Oracle Compute Instance
This was driving me potty. Although I have finally found a solution by using the dnsname CNI plugin for Podman.
First, let's confirm we have a problem on our box, by creating a new network and 2 test containers, to see if they can communicate with each other
docker network create mynetwork
podman run -d --name node0 --network mynetwork docker.io/alpine:latest sleep inf
podman run -d --name node1 --network mynetwork docker.io/alpine:latest sleep inf
podman exec -it node0 ping -c2 node1
A successful result would be
PING node1 (10.89.0.17): 56 data bytes
64 bytes from 10.89.0.17: seq=0 ttl=64 time=0.159 ms
64 bytes from 10.89.0.17: seq=1 ttl=64 time=0.069 ms
--- node1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.069/0.114/0.159 ms
However, if the result is...
ping: bad address 'node1'
...then we need to follow these steps to fix this & all future networks.
Install the following tools
sudo dnf install git -y sudo dnf install golang -y sudo dnf install dnsmasq -y sudo dnf install nano -y
Clone the dnsname repository:
git clone https://github.com/containers/dnsname.git
Build the plugin using golang
cd dnsname make
Copy the plugin into the directory with the other CNI plugins:
sudo cp bin/dnsname /usr/libexec/cni
Add support for
dnsname
to one or more Podman networks. All networks will appear in/home/opc/.config/cni/net.d
so in this example, we will edit themynetwork
networknano /home/opc/.config/cni/net.d/mynetwork.conflist
Paste the following
{ "type": "dnsname", "domainName": "dns.podman", "capabilities": { "aliases": true } },
at a new line directly after
"plugins": [
so that it looks like this at the top of the file.{ "cniVersion": "0.4.0", "name": "mynetwork", "plugins": [ { "type": "dnsname", "domainName": "dns.podman", "capabilities": { "aliases": true } }, { "type": "bridge", "bridge": "cni-podman1", "isGateway": true, "ipMasq": true,
CTRL+X to save the file & exit the editor
Remove the containers & retest
# Remove podman stop node0 podman stop node1 podman rm node0 podman rm node1 podman network rm mynetwork # create docker network create mynetwork podman run -d --name node0 --network mynetwork docker.io/alpine:latest sleep inf podman run -d --name node1 --network mynetwork docker.io/alpine:latest sleep inf podman exec -it node0 ping -c2 node1
If this works, we should see a ping success
PING node1 (10.89.0.17): 56 data bytes 64 bytes from 10.89.0.17: seq=0 ttl=64 time=0.159 ms 64 bytes from 10.89.0.17: seq=1 ttl=64 time=0.069 ms --- node1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.069/0.114/0.159 ms
Tidy up the test by removing the test containers
# Remove podman stop node0 podman stop node1 podman rm node0 podman rm node1 podman network rm mynetwork
BONUS FEATURE: Once the dnsname plugin is installed, it will be enabled by default on all new networks. I.e after installing
dnsname
, all new networks on my Compute box had the plugin enabledENJOY
Credits to Larsks for this post. I adapted his solution to Oracle Compute Unix.
What's the picture? It's Brothers Water in Cumbria. Visit Cumbria ... and Yorkshire too.