Make the container's root filesystem read-only
A process that gets code execution in a writable container can drop a binary next to yours or patch a file in place, and it stays there until the container restarts. Take write access away and give back only the paths the app really needs.
services:
web:
read_only: true
tmpfs:
- /tmpdocker run --read-only --tmpfs /tmp does the same. Turn it on locally first and let it crash. The errors name every path the app writes to, and the list is usually shorter than anyone guessed.
dockersecurity