Most services never need to write to their own filesystem. Docker lets you enforce that, and it takes one flag.
--read-only mounts the container’s root filesystem read-only. Anything that really needs to write gets its own writable spot, such as a volume or a tmpfs.
docker run -d --read-only \
--tmpfs /tmp:rw,noexec,nosuid,size=64m \
-v appdata:/data \
myimage
The tmpfs lives in memory and vanishes with the container. The options after it are the same ones you would give to mount -t tmpfs -o. In compose the matching keys are read_only: true and tmpfs: [/tmp].
It limits the damage if something in the container gets compromised, since it can no longer drop files into the filesystem. It is not a complete defence, but it is cheap, and it fits well with running as a non-root user.
The caveat is that apps are not always honest about where they write. Expect the first start to fail with a permission error on some path such as /run or a cache directory. Read the error, add that path as a tmpfs or a volume, and try again. I think the extra ten minutes are worth it for anything facing the internet.
Further reading: docker container run: read-only and tmpfs, On this site: docker update –restart changes the policy without recreating the container, On this site: docker cp works on stopped containers too