Understanding Docker Weirdness: A Practical Guide to Container Quirks

Understanding Docker Weirdness: A Practical Guide to Container Quirks
Photo by Wolfgang Weiser on Pexels

Understanding Docker Weirdness: A Practical Guide to Container Quirks

A recent article titled “Docker is weird” has been making waves across tech communities, and honestly? It’s about time someone said it out loud. Docker has become so ubiquitous in modern infrastructure that we’ve normalized its quirks, but these oddities still trip up even seasoned Linux administrators. Today, we’re going to dig into the practical implications of Docker’s weirdness and arm you with the knowledge to handle its most confusing behaviors in production environments.

Table of Contents

Why Docker Feels Weird to Traditional Sysadmins

If you’ve spent years mastering traditional Linux system administration, Docker probably feels like someone changed all the rules midgame. That’s because it did. Docker sits in this uncomfortable middle ground between virtual machines and native processes, borrowing concepts from both worlds while fully committing to neither.

The core weirdness stems from Docker’s use of Linux namespaces and cgroups—powerful kernel features that most sysadmins never touched directly before containerization. When you run a container, you’re not spinning up a new kernel or even a full userspace. You’re creating an isolated view of the existing system, which leads to behaviors that violate our intuitions about how processes, networks, and filesystems should work.

For professionals looking to deepen their understanding of container orchestration and cloud-native architectures, platforms like Coursera offer specialized tracks that cover these modern infrastructure patterns in production contexts.

The Networking Layer: Where Logic Goes to Die

Docker networking is where most of the “weirdness” complaints originate, and rightfully so. By default, Docker creates a virtual bridge network and assigns containers private IP addresses that exist in a separate network namespace. This means a container can have an IP address that’s completely invisible to the host’s normal networking stack.

The Port Publishing Puzzle

Consider this scenario: you start a web server inside a container listening on port 80. You can see it’s running inside the container, but you can’t reach it from your host or external network. Why? Because that port 80 exists only in the container’s network namespace. To make it accessible, you need to explicitly publish it:

# Start nginx in a container and publish port 80 to host port 8080
docker run -d -p 8080:80 nginx

# Verify the port mapping and container network configuration
docker port $(docker ps -lq)

What’s actually happening here is Docker is setting up iptables NAT rules to forward traffic from the host’s port 8080 to the container’s port 80. You can see this with iptables -t nat -L -n, where you’ll find Docker has created an entire chain of rules. This approach works, but it’s fundamentally different from how you’d configure a traditional service on a Linux host.

⚠️ Common Mistake: Binding to localhost (127.0.0.1) inside your container won’t work with Docker’s port publishing. Your application must listen on 0.0.0.0 or the container’s IP to accept forwarded connections from the host.

DNS Resolution Quirks

Docker also injects its own DNS server into containers at 127.0.0.11 (yes, that’s intentionally not a typo). This internal DNS resolver handles container name resolution for Docker’s internal networks, but it can cause confusion when debugging connectivity issues. If your container can’t resolve external hostnames, you might need to specify custom DNS servers explicitly.

Filesystem Layers and the Persistence Problem

Docker’s layered filesystem using union mounts (typically OverlayFS on modern systems) is elegant in theory but weird in practice. Every change you make in a container creates a new layer on top of the read-only image layers, and these changes disappear when the container is removed unless you’ve used volumes or bind mounts.

This leads to a common source of confusion: you install something in a running container, restart it, and your changes are gone. That’s not a bug—it’s a feature. Containers are meant to be ephemeral, with all persistent data stored externally.

Volume Mounting Gotchas

Here’s where things get particularly weird. When you mount a host directory into a container, ownership and permissions can behave unexpectedly because the container’s user namespace might map UIDs differently than your host:

# Create a bind mount and check ownership inside the container
docker run -it -v /host/data:/container/data ubuntu:latest bash
# Inside container: ls -ln /container/data
# The numeric UID might not match what you expected from the host

# Using named volumes (managed by Docker) avoids some of these issues
docker volume create mydata
docker run -it -v mydata:/container/data ubuntu:latest

Named volumes are Docker-managed and stored in /var/lib/docker/volumes/ by default, but their contents are effectively opaque to normal system tools. You can’t easily back them up with standard filesystem tools without stopping containers or using Docker-specific commands.

💡 Pro Tip: Use docker volume inspect volume_name to find the actual mountpoint on your host filesystem. This is invaluable when you need to troubleshoot volume issues or perform emergency data recovery.

Process Management: Not Your Father’s Init System

In traditional Linux systems, PID 1 is the init system (systemd, SysV init, etc.) which has special responsibilities for reaping zombie processes and handling signals. Docker containers typically run a single process as PID 1, and that process inherits these responsibilities without necessarily being designed for them.

This creates weird scenarios where signals don’t behave as expected. For example, docker stop sends SIGTERM to PID 1, expecting a graceful shutdown. If your application doesn’t handle SIGTERM properly, Docker waits 10 seconds and then sends SIGKILL. But if PID 1 is a shell script that’s not properly forwarding signals to child processes, those children never get the shutdown signal at all.

For IT professionals working with containerized infrastructure and looking to build robust orchestration skills, DataCamp offers hands-on courses covering container management and modern DevOps practices.

Practical Debugging Techniques for Docker Weirdness

When Docker behaves weirdly, you need tools to peek under the hood. Here are some essential debugging techniques that work with Docker’s architecture rather than against it.

Inspecting Container Internals

The docker inspect command dumps a JSON blob with everything Docker knows about a container, including its network configuration, mounts, environment variables, and current state. Combine it with jq for surgical precision:

# Get the container's IP address in the default bridge network
docker inspect container_name | jq -r '.[0].NetworkSettings.Networks.bridge.IPAddress'

# Find all bind mounts for a running container
docker inspect container_name | jq -r '.[0].Mounts[] | select(.Type=="bind") | .Source'

For network debugging, remember that nsenter lets you enter a container’s network namespace from the host, giving you full access to standard networking tools without needing them installed in the container image:

# Enter the network namespace of a container and run tcpdump
# First get the PID of the container's main process
PID=$(docker inspect -f '{{.State.Pid}}' container_name)
# Then use nsenter to run commands in that namespace
nsenter -t $PID -n tcpdump -i eth0 port 80

Understanding Resource Constraints

Docker uses cgroups to enforce resource limits, but these limits don’t always surface in ways applications expect. A container might think it has 32 CPU cores available (because that’s what the host has) even though Docker has limited it to 1 core equivalent. This causes application auto-tuning to make terrible decisions about thread pools and parallelism.

Check what a container actually sees versus what it’s limited to using the /sys/fs/cgroup filesystem inside the container. This is particularly important for JVM-based applications which historically ignored cgroup limits entirely until recent versions.

💡 Pro Tip: Always set explicit memory and CPU limits for production containers. Unlimited containers can trigger OOM killer behavior that affects the entire host, and chasing down which container caused a system-wide memory pressure event is no fun at 3 AM.

Log Management Reality

Docker captures stdout and stderr from PID 1 and stores them using a logging driver (json-file by default). This means traditional log files written to /var/log inside a container are invisible to docker logs unless you explicitly symlink them to stdout/stderr or configure your application to log to the console.

For production systems, configure a proper logging driver (journald, syslog, or a third-party solution) rather than relying on the default json-file driver, which doesn’t rotate logs automatically and can fill up your disk with container output.

Embracing the Weirdness

Docker is weird, but its weirdness is mostly consistent once you understand the underlying mechanisms. The key is recognizing that containers are neither VMs nor traditional processes—they’re a distinct abstraction layer with their own rules and behaviors.

Instead of fighting against Docker’s design, learn to work with its model. Use volumes for persistent data, design applications to log to stdout, handle signals properly, and treat containers as disposable. The weirdness becomes less weird once you stop expecting containers to behave like full virtual machines or traditional daemons.

The productivity gains from containerization are real, but they require a shift in mental models. What seems weird at first eventually becomes second nature, and you’ll find yourself reaching for Docker even for local development because of how elegantly it solves environment consistency problems—weird behaviors and all.

Stay in the loop — join 125,000+ IT professionals following Networkyy: Instagram · Facebook · Threads · Medium
🔥 RECOMMENDED FOR YOU

Master Container Orchestration at Scale

Go beyond Docker basics and learn Kubernetes, service meshes, and cloud-native patterns that power modern infrastructure. Get hands-on with real production scenarios from industry experts.

Start Learning on Coursera →

Retour en haut