Advent of Sysadmin 2026

Welcome back to another year of Advent challenges!

For some reason I thought Advent of Sysadmin this year would start 12 days before Christmas, but I was hugely mistaken. So here I am, 4 days in, only now bringing us up to speed. If you've been waiting to solve yet another set of awesome challenges this year, welcome, and let's have fun together!

Task from December 1 is now available!

Title image

Los Algodones: App container cannot reach Redis #

Description

Two Docker containers are running: a small web app (app) on port :80 and a Redis cache (redis). The app is supposed to use Redis, but the page shows it cannot connect.

curl -s http://127.0.0.1/ returns:
Error: cannot connect to Redis

Redis itself is running. The app configures its Redis connection with the REDIS_HOST environment variable (see /home/admin/algodones).

Just from the task description I have a feeling this is a network/DNS issue. Let's verify if my assumptions are correct. We have two containers running:

bashadmin@i-0038af8637b48ed6b:~$ docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED       STATUS          PORTS                                         NAMES
8b860d451d91   algodones-app:1.0    "python /app/app.py"     2 weeks ago   Up 44 seconds   0.0.0.0:80->80/tcp, [::]:80->80/tcp           app
e4e4eb317a09   redis:7.4.2-alpine   "docker-entrypoint.s…"   2 weeks ago   Up 44 seconds   0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp   redis

Let's see if the containers are on the same network.

bashadmin@i-0038af8637b48ed6b:~$ docker inspect app redis 
[
    {
        "Id": "8b860d451d91e9ede96928fb46f3860a4ecb82755eee9a33d7692e1c11948eb7",
        ...
        "NetworkSettings": {
          ...
            "Networks": {
                "bridge": {...}
            }
        },
        ...
    },
    {
        "Id": "e4e4eb317a09b6c7bebb8a9e554a49623df8bd7a500b15f1f0b86324840365b8",
        ...
        "NetworkSettings": {
          ...
            "Networks": {
                "bridge": {...}
            }
        },
        ...
    }
]

Well, they are connected to the same bridge interface, but that doesn't mean they can communicate directly via DNS names.

bashadmin@i-0038af8637b48ed6b:~$ docker exec -ti redis /bin/sh
/data # cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::  ip6-localnet
ff00::  ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3      e4e4eb317a09
/data # traceroute app
traceroute: bad address 'app'
/data # traceroute 172.17.0.2
traceroute to 172.17.0.2 (172.17.0.2), 30 hops max, 46 byte packets
 1  ip-172-17-0-2.us-east-2.compute.internal (172.17.0.2)  0.008 ms  0.004 ms  0.005 ms

And the assumption was correct -- direct IP addresses are reachable, but DNS names are unresolvable. That's because the default bridge network Docker creates doesn't provide DNS resolution for containers. But we can be sly and crack the solution!

bashadmin@i-0038af8637b48ed6b:~$ docker exec -ti app /bin/sh
/app # cd /etc/
/etc # vim hosts
/bin/sh: vim: not found # why no one ever has vim
/etc # cat hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::  ip6-localnet
ff00::  ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      8b860d451d91
/etc # echo "172.17.0.3 e4e4eb317a09 redis" >> hosts
/etc # 
admin@i-0038af8637b48ed6b:~$ curl -s http://127.0.0.1/
OK
admin@i-0038af8637b48ed6b:~$ bash /home/admin/agent/check.sh
OK

What happens here: one of the ways hosts can discover each other's domain names is by assigning names directly in the /etc/hosts file. This is a solution, but it will last only as long as the container isn't restarted (unless the hosts file is mounted onto a persistent file system). The other way to reach the same result would be to create another network and attach both containers to that network:

bashadmin@i-0038af8637b48ed6b:~$ docker network create sadservers
ab05bd8f8ce4befadf24a0d7fdb4f4b5255f3306a075c47da4319d0d005c581a
admin@i-0038af8637b48ed6b:~$ docker network ls
NETWORK ID     NAME         DRIVER    SCOPE
844715640ba0   bridge       bridge    local
28e384471931   host         host      local
6ce2f5bad1bf   none         null      local
ab05bd8f8ce4   sadservers   bridge    local
admin@i-0038af8637b48ed6b:~$ docker network connect sadservers app
admin@i-0038af8637b48ed6b:~$ docker network connect sadservers redis
admin@i-0038af8637b48ed6b:~$ curl -s http://127.0.0.1/
OK
admin@i-0038af8637b48ed6b:~$ bash agent/check.sh
OK

But where's the fun in that?


Reply to this post ✉️