Los Algodones - Advent of Sysadmin 2026
Advent of Sysadmin 2026 🎄
This is part of Sad Servers' Advent of Sysadmin 2026 series.
I'm doing each challenge and publishing a quick write-up for each one every day.
Spoiler alert! This gives the solution to the challenge. If you want to do it on your own, stop reading.
🤖 AI Notice: Unless clearly mentioned, no AI was used to solve the challenges themselves. I use AI only for proofreading my write-ups.
Challenge details
Scenario: "Los Algodones": App container cannot reach Redis - https://sadservers.com/scenario/los-algodones
Level: Easy
Type: Fix
Access: Public
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).
Root (sudo) Access: True
Test: curl -s http://127.0.0.1/ returns OK. From inside the app container, Redis is reachable by the hostname redis.
The "Check My Solution" button runs the script /home/admin/agent/check.sh, which you can see and execute.
Time to Solve: 15 minutes.
Welcome back to another Advent of Sysadmin!
This year's first challenge is about Docker networking. Two containers running on the bridge network can't reach one another, it seems. Let's run some exploratory commands.
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b860d451d91 algodones-app:1.0 "python /app/app.py" 13 days ago Up 28 seconds 0.0.0.0:80->80/tcp, [::]:80->80/tcp app
e4e4eb317a09 redis:7.4.2-alpine "docker-entrypoint.s…" 13 days ago Up 28 seconds 0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp redis
~$ docker inspect redis app | grep "NetworkMode"
"NetworkMode": "bridge",
"NetworkMode": "bridge",
~$ docker network ls
NETWORK ID NAME DRIVER SCOPE
a92f8553c201 bridge bridge local
28e384471931 host host local
6ce2f5bad1bf none null local
~$ docker network inspect bridge | grep default
"Driver": "default",
"com.docker.network.bridge.default_bridge": "true",
~$ curl -v http://127.0.0.1/
* Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80
* using HTTP/1.x
> GET / HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/8.14.1
> Accept: */*
>
* Request completely sent off
* HTTP 1.0, assume close after body
< HTTP/1.0 503 Service Unavailable
< Server: BaseHTTP/0.6 Python/3.12.8
< Date: Wed, 02 Dec 2026 18:06:42 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 30
<
* shutting down connection #0
Error: cannot connect to Redis
We have the source code of what's running on port 80. Let's look at it:
# /home/admin/algodones/app.py
#!/usr/bin/env python3
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
import redis
REDIS_HOST = os.environ.get("REDIS_HOST", "redis")
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
def redis_ok():
try:
client = redis.Redis(
host=REDIS_HOST,
port=REDIS_PORT,
socket_connect_timeout=1,
socket_timeout=1,
)
return bool(client.ping())
except Exception:
return False
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path not in ("/", "/health"):
self.send_response(404)
self.end_headers()
return
ok = redis_ok()
body = b"OK" if ok else b"Error: cannot connect to Redis"
self.send_response(200 if ok else 503)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, fmt, *args):
return
if __name__ == "__main__":
HTTPServer(("0.0.0.0", 80), Handler).serve_forever()
So the app container reaches Redis using the environment variables REDIS_HOST and REDIS_PORT. Both have default values that should be fine in theory.
Let's check the app container environment variables:
~$ docker exec app env
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8b860d451d91
REDIS_HOST=redis
REDIS_PORT=6379
LANG=C.UTF-8
GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305
PYTHON_VERSION=3.12.8
PYTHON_SHA256=c909157bb25ec114e5869124cc2a9c4a4d4c1e957ca4ff553f1edc692101154e
HOME=/root
In theory, everything looks fine. Port is OK, host is OK. But as we learnt by inspecting both containers, they are running on the default bridge network, and app relies on resolving the hostname redis through DNS. Can we prove that the issue is DNS resolution?
Neither container image has much tooling for this (we can't docker exec into them and run dig or host). Instead, we can use nsenter to run a host binary inside the container's network namespace, or use the container's Python directly.
First, is redis reachable at all from app, using its IP address?
~$ docker inspect redis --format '{{.NetworkSettings.IPAddress}}'
172.17.0.2
~$ sudo nsenter -t $(docker inspect app --format '{{.State.Pid}}') -n telnet 172.17.0.2 6379
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'
It is, so the network itself is fine. Now, can app resolve the name redis?
~$ docker exec app cat /etc/resolv.conf
# Generated by Docker Engine.
# This file can be edited; Docker Engine will not make further changes once it
# has been modified.
nameserver 10.1.0.2
search .
# Based on host file: '/run/systemd/resolve/resolv.conf' (legacy)
# Overrides: []
~$ sudo nsenter -t $(docker inspect app --format '{{.State.Pid}}') -n host redis 10.1.0.2
Using domain server:
Name: 10.1.0.2
Address: 10.1.0.2#53
Aliases:
Host redis not found: 3(NXDOMAIN)
~$ docker exec app python -c "import socket; print(socket.gethostbyname('redis'))"
No. The container uses the host's upstream DNS server (10.1.0.2), which has never heard of redis. Let's check the docs to understand why:
When you start Docker, a default bridge network (also called bridge) is created automatically, and newly-started containers connect to it unless otherwise specified.
Containers on the default bridge network can only access each other by IP addresses [...]. On a user-defined bridge network, containers can resolve each other by name or alias.
By default, containers inherit the DNS settings as defined in the /etc/resolv.conf configuration file. Containers that attach to the default bridge network receive a copy of this file. Containers that attach to a custom network use Docker's embedded DNS server. The embedded DNS server forwards external DNS lookups to the DNS servers configured on the host. The embedded DNS server address is 127.0.0.11.
Now we know it's DNS: on the default bridge network, containers can't resolve each other by name. What can we do?
- Fix the networking: create a new bridge network, attach both containers
- Fix the environment variable to point to the container's IP
Option 2 is not really sustainable as the container's IP could change. Let's do option 1:
~$ docker network create algo
~$ docker network connect algo app
~$ docker network connect algo redis
~$ curl -v http://127.0.0.1/
* Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80
* using HTTP/1.x
> GET / HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/8.14.1
> Accept: */*
>
* Request completely sent off
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.12.8
< Date: Wed, 02 Dec 2026 19:06:23 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 2
<
* shutting down connection #0
OK
No restart needed: it works straight away! When app joined algo, Docker rewrote its /etc/resolv.conf to point to the embedded DNS server (127.0.0.11). Running the same checks as before confirms it:
~$ docker exec app cat /etc/resolv.conf
# Generated by Docker Engine.
# This file can be edited; Docker Engine will not make further changes once it
# has been modified.
nameserver 127.0.0.11
search .
options ndots:0
# Based on host file: '/run/systemd/resolve/resolv.conf' (internal resolver)
# ExtServers: [host(10.1.0.2)]
# Overrides: []
# Option ndots from: internal
~$ docker exec app python -c "import socket; print(socket.gethostbyname('redis'))"
172.18.0.3
~$ sudo nsenter -t $(docker inspect app --format '{{.State.Pid}}') -n host redis 127.0.0.11
Using domain server:
Name: 127.0.0.11
Address: 127.0.0.11#53
Aliases:
redis has address 172.18.0.3
Host redis not found: 3(NXDOMAIN)
As they say: it's always DNS. 🚩
- ← Previous
What's cleaning /tmp on macOS?