Docker: mount image’s original / to a volume in read/write mode

I try to mount image’s original / to a volume in read/write mode, in order to be able to change it easily from outside (without entering the container) and then restart the container to observe the changes.

I do it (in ansible) like this:


If /app/ doesn’t exist on the host, a directory /app/ (not a file, as wish) is created, and I get following error:

Error starting container e40a90eef1525f554e6078e20b3ab5d1c4b27ad2a7d73aa3bf4f7c6aa337be4f: 400 Client Error: Bad Request ("OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\"/app/\\" to rootfs \\"/var/lib/docker/devicemapper/mnt/4d3e4f4082ca621ab5f3a4ec3f810b967634b1703fd71ec00b4860c59494659a/rootfs\\" at \\"/var/lib/docker/devicemapper/mnt/4d3e4f4082ca621ab5f3a4ec3f810b967634b1703fd71ec00b4860c59494659a/rootfs/\\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

If I touch /app/ (and set proper permissions) before launching the container – the container fails to start up and keeps restarting (I assume because the /app/ and therefore internal / are empty).

How can I mount the original content of container’s / to the outside?

Source: StackOverflow