---
title: "Docker Read-Only File Systems - Muhammad Rehan Saeed"
description: "How to use a read-only file system in Docker to secure your Docker containers using the docker run CLI command and Docker compose or docker swarm."
canonical_url: "https://rehansaeed.com/docker-read-file-systems/"
last_updated: "2017-11-13T00:00:00+00:00"
meta:
  author: "Muhammad Rehan Saeed"
  keywords: "ASP.NET Core,Docker,Docker Compose,Docker Swarm,File System"
  "og:description": "How to use a read-only file system in Docker to secure your Docker containers using the docker run CLI command and Docker compose or docker swarm."
  "og:image": "https://rehansaeed.com/_og/s/o_35b0641526a813be.png"
  "og:image:alt": "Docker Read-Only File Systems - Muhammad Rehan Saeed"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Docker Read-Only File Systems"
  "twitter:image": "https://rehansaeed.com/_og/s/o_35b0641526a813be.png"
  "twitter:image:alt": "Docker Read-Only File Systems - Muhammad Rehan Saeed"
---

> Index of every page on this site: [llms.txt](https://rehansaeed.com/llms.txt)

# [Docker Read-Only File Systems](https://rehansaeed.com/docker-read-file-systems/)

Posted 13 November 2017 - **1 min read**

![Docker](https://rehansaeed.com/_ipx/f_png&s_2560x1440/images/hero/Docker-1366x768.png)

For a little bit of added security you can make the file system of your container read-only, excluding any volumes you may have created. If anyone hacks into your container, they will be unable to change any files.

# Docker Run

When using the docker run command using the CLI, you can simply use the following command:

```powershell
docker run --read-only redis
```

# Docker Compose/Swarm

To set a read-only file system, you simply need to set the `read_only` flag to `true`, like so:

```yaml
version: '3.3'

services:
  redis:
    image: redis:4.0.1-alpine
    networks:
      - myoverlay
    read_only: true
    
networks:
  myoverlay:
```

So above, I have a Docker stack file for use with Docker Swarm showing how to start Redis with a read-only file system.

# What is Supported?

Not all images support having them started with a read-only file system. Some require access to write temp files and the like. You can usually get away with using a volume in this case because volumes are still writeable even if you enable the read-only file system. In my research, I found it hard to determine if an image supported the feature, so I simply tried it out and found that most failed.

I discovered that Redis was the only image that I was running that had [full support](https://github.com/docker-library/redis/issues/109), several Elastic Stack containers failed to start and even my ASP.NET Core images failed to start. I since raised a GitHub issue [here](https://github.com/Microsoft/aspnet-docker/issues/66), trying to find out why the container fails to start and seeing if there is any workaround.

## Web Mentions

[What's this?](https://en.wikipedia.org/wiki/Webmention)

### 0 Linked

### 0 Replies

## GitHub Comments

### 0 Comments

[Comment on GitHub](https://github.com/RehanSaeed/rehansaeed.github.io/issues/72)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://rehansaeed.com/#website","@type":"WebSite","description":"Software Developer at Microsoft, YouTuber, Open Source Contributor and Blogger","inLanguage":"en-GB","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com/","author":{"@id":"https://rehansaeed.com/#identity"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://rehansaeed.com/?search={search_term_string}"},"query-input":"required name=search_term_string"}],"publisher":{"@id":"https://rehansaeed.com/#publisher"}},{"@id":"https://rehansaeed.com/docker-read-file-systems/#webpage","@type":"WebPage","dateModified":"2017-11-13T00:00:00+00:00","datePublished":"2017-11-13T00:00:00+00:00","description":"How to use a read-only file system in Docker to secure your Docker containers using the docker run CLI command and Docker compose or docker swarm.","name":"Docker Read-Only File Systems","url":"https://rehansaeed.com/docker-read-file-systems/","breadcrumb":{"@id":"https://rehansaeed.com/docker-read-file-systems/#breadcrumb"},"isPartOf":{"@id":"https://rehansaeed.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://rehansaeed.com/docker-read-file-systems/"]}]},{"@id":"https://rehansaeed.com/#identity","@type":"Person","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com/about/","image":{"@id":"https://rehansaeed.com/#/schema/image/1"},"sameAs":["https://github.com/RehanSaeed","https://www.linkedin.com/in/muhammad-rehan-saeed","https://stackoverflow.com/users/1212017/muhammad-rehan-saeed","https://www.youtube.com/c/MuhammadRehanSaeed","https://www.twitch.tv/rehansaeeduk"]},{"@id":"https://rehansaeed.com/#publisher","@type":"Organization","logo":"https://rehansaeed.com/images/schema/Publisher-600x60.png","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com"},{"@id":"https://rehansaeed.com/docker-read-file-systems/#article","@type":"Article","dateModified":"2017-11-13T00:00:00+00:00","datePublished":"2017-11-13T00:00:00+00:00","description":"How to use a read-only file system in Docker to secure your Docker containers using the docker run CLI command and Docker compose or docker swarm.","headline":"Docker Read-Only File Systems","inLanguage":"en-GB","url":"https://rehansaeed.com/docker-read-file-systems/","author":{"@id":"https://rehansaeed.com/#identity"},"image":[{"@type":"ImageObject","url":"https://rehansaeed.com/images/hero/Docker-1366x768.png","caption":"Docker","width":"1366","height":"768"}],"isPartOf":{"@id":"https://rehansaeed.com/docker-read-file-systems/#webpage"},"keywords":["ASP.NET Core","Docker","Docker Compose","Docker Swarm","File System"],"mainEntityOfPage":{"@id":"https://rehansaeed.com/docker-read-file-systems/#webpage"},"publisher":{"@id":"https://rehansaeed.com/#publisher"}},{"@id":"https://rehansaeed.com/docker-read-file-systems/#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Blog","item":"https://rehansaeed.com/","position":1},{"@type":"ListItem","name":"Docker Read-Only File Systems","item":"https://rehansaeed.com/docker-read-file-systems/","position":2}]},{"@id":"https://rehansaeed.com/#/schema/image/1","@type":"ImageObject","contentUrl":"https://rehansaeed.com/images/author/Muhammad-Rehan-Saeed/Logo-512x512.png","inLanguage":"en-GB","url":"https://rehansaeed.com/images/author/Muhammad-Rehan-Saeed/Logo-512x512.png"}]}
```

## Sitemap

See the full [sitemap](https://rehansaeed.com/sitemap.md) for all pages.
