Previous: , Up: Guix System Containers   [Contents][Index]

4.2.2 Container Networking

What good is a Guix System running a PostgreSQL database service as a container when we can only talk to it with processes originating in the container? It would be much better if we could talk to the database over the network.

The easiest way to do this is to create a pair of connected virtual Ethernet devices (known as veth). We move one of the devices (ceth-test) into the net namespace of the container and leave the other end (veth-test) of the connection on the host system.


# Attach the new net namespace "guix-test" to the container PID.
sudo ip netns attach $ns $pid

# Create the pair of devices
sudo ip link add $host type veth peer name $client

# Move the client device into the container's net namespace
sudo ip link set $client netns $ns

Then we configure the host side:

sudo ip link set $host up
sudo ip addr add dev $host

…and then we configure the client side:

sudo ip netns exec $ns  ip link set lo up
sudo ip netns exec $ns  ip link set $client up
sudo ip netns exec $ns  ip addr add dev $client

At this point the host can reach the container at IP address, and the container can reach the host at IP This is all we need to talk to the database server inside the container from the host system on the outside.

$ psql -h -U test
psql (14.4)
Type "help" for help.

test=> CREATE TABLE hello (who TEXT NOT NULL);
test=> INSERT INTO hello (who) VALUES ('world');
test=> SELECT * FROM hello;
(1 row)

Now that we’re done with this little demonstration let’s clean up:

sudo kill $pid
sudo ip netns del $ns
sudo ip link del $host

Previous: A Database Container, Up: Guix System Containers   [Contents][Index]