Life and Shell

Writing · ubuntu

A Powerful Technique: Modifying a Host System from Within a Docker Container

By Mattias Hemmingsson · · 1 min read

Use Containers to Manage Your Server’s Configuration

The ‘Ubuntu System Administration Guide’ introduces an advanced and powerful pattern used in modern infrastructure management, particularly with Kubernetes: using a container to modify the host system it’s running on. This allows you to package your configuration tools into a container and run them safely against your server.

How It Works: Volume Mounting

The key to this technique is mounting parts of the host’s filesystem into the container. The book provides a simple example where the host’s `/etc` directory is mounted into the container at `/mnt/etc`:

volumes:
  - /etc:/mnt/etc

From inside the container, you can now read and write files in `/mnt/etc`, which directly modifies the files in `/etc` on the host. This allows you to run a container with specific tools (like `sed`, `awk`, or a custom script) to perform a configuration update without having to permanently install those tools on the host server.


This post is based from content of the book Ubuntu System adminstration guide. And the book can be found here https://www.amazon.com/stores/Mattias-Hemmingsson/author/B0FF5CQX13

Filed underbpd · ubuntu