Govur University Logo
--> --> --> -->
...

What specific flag can be applied when starting a Docker container to prevent any writes to its root filesystem, thereby enhancing its security posture?



The specific flag that can be applied when starting a Docker container to prevent any writes to its root filesystem is `--read-only`. When this flag is used, the container's root filesystem is mounted as read-only. The root filesystem is the primary directory structure that a Docker container perceives and uses, containing its operating system files, installed applications, and their default configurations. By making this filesystem read-only, Docker prevents any new files from being created, existing files from being modified, or any files from being deleted within that fundamental part of the container. This significantly enhances the container's security posture because it restricts malicious software or unintended processes from writing to critical system files, altering configurations, or persisting data directly onto the container's core installation. For applications that genuinely require write access for their operational data, such as logs, temporary files, or database storage, Docker volumes or bind mounts must be explicitly used. A Docker volume is a distinct and persistent storage mechanism that exists independently of the container's ephemeral writable layer. When a volume is mounted into a container, even one started with the `--read-only` flag, that specific mounted volume retains its full write capabilities. This design allows applications to store their mutable data in designated, writable locations while the core root filesystem remains immutable, preserving its integrity and improving security.