I have a Docker image that contains two configuration files and merges them using sed
depending on the passed environment variables in the entrypoint script. To simplify this merge step, you can assume something like
if [ -n $MERGE ]; then
sed -i s/a/b/ /config.json
fi
The person who wrote this entrypoint script didn't consider the main use-case where config.json
is mounted into the container. In that case, this script produces the error message
sed: cannot rename ./sedahi0e3: Device or resource busy
because sed
writes its changes into a tempfile and overwrites the original file. As I said, this is a simplification of my actual problem, so most workarounds for this won't work. I just want to know if it's somehow possible to mount config.json
into the container and allow it to be overwritten, deleted or shadowed. It's not so important, what happens with the original file on the host file system. In the best case, it's not modified, but I could accept it to be deleted or modified. If it's not possible, I have to modify the script in a complex and error-prone way, that could break some edge cases of configuration, I don't know about.
Can I mount a file into a Docker container in a way, that it can be overwritten, deleted or shadowed inside the container? The image is based on Alpine Linux. The host is either Debian or RHEL.
To reproduce the problem, you can create a file config.json
. Start an Alpine container with
docker run -v $PWD/config.json:/config.json -it --rm alpine sh
copy the file
cp /config.json /config2.json
and try to overwrite the mounted file with the copy
mv /config2.json /config.json
That's similar to what the sed
merge in the entrypoint script does and produces the same error.