Copy-on-write lets a container edit a file from a read-only image layer without changing the image. Docker copies the file into the container’s writable layer, then applies edits there. section 6.1
The storage behavior follows a simple sequence:
- The container reads the original file from an image layer. section 6.1
- An edit triggers a copy into the container’s writable layer. section 6.1
- The changed file affects that container only; the image and other containers remain unchanged. section 6.1
Change a file inside a container
Run the file-display container, copy a replacement file to /input.txt, and start it with attachment. The same container then displays the new contents, while a new container uses the image’s original file.
docker container run --name f1 diamol/ch06-file-display:2e echo "https:/./blog.sixeyed.com" > url.txt docker container cp url.txt f1:/input.txt docker container start --attach f1
Use the runnable command sequence to observe copy-on-write through a file edit and the container’s subsequent output. section 6.1




