How to Secure Docker Containers with a Read-Only Filesystem

Ben Lobaugh
5 min readJan 10, 2021
<span>Photo by <a href=”https://unsplash.com/@nicoli_?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyT
Photo by Chepe Nicoli on Unsplash

A compromised website sucks. A compromised website that an attacker can insert code into to manipulate your visitors is even worse! Out-of-the-box, Docker containers provide some security advantages over running directly on the host, however Docker provides additional features to increase security. There is a little known flag in Docker that will convert a container’s files system to read-only.

My father runs an e-commerce site for his dahlia flower hobby business at https://lobaughsdahlias.com. Many years ago, a hacker was able to gain access to the site files through FTP, and then injected a bit of code into the head of the theme. That code was capturing data about customers and sending it to a server in Russia. Luckily the issue was caught before any sensitive data was sent out, but it served to highlight the many layers it takes to secure a website.

Security is like an onion, peel back one layer and another reveals itself beneath. If the filesystem had been read-only, the attacker still would have been able to get in, but they would have been unable to alter anything on the filesystem, thus rendering their end goal moot.

To simplify securing a container, Docker provides a read-only runtime flag that will enforce the filesystem into a read-only state.

--

--

Ben Lobaugh

Director of Engineering at Mindsize. 20+ year technology veteran. Providing leadership insights, mentorship, and coaching to new and existing leaders.