config.json in container and 'Device or resource busy'
Bug report information
Description
In docker-entrypoint.sh there is a command:
...
mv config.json.tmp config.json
...
It works fine as long as no-one wants to mount external config.json file (docker run -v $(pwd)/config.json:/usr/src/app/config.json ...). If so "docker" fails with the error:
mv: cannot move 'config.json.tmp' to 'config.json': Device or resource busy
The reason is that Linux does not allow to delete/rename mount points (mv uses actually rename() syscall).
One of the possible solutions is to replace "mv" with 2 commands:
--- old/docker-entrypoint.sh 2021-08-31 07:47:00.832079384 +0000
+++ new/docker-entrypoint.sh 2021-08-31 07:47:30.516815669 +0000
@@ -197,7 +197,8 @@
if [[ $JQ_FILTERS_CONFIG != "." ]]; then
jq "$JQ_FILTERS_CONFIG" config.json > config.json.tmp
- mv config.json.tmp config.json
+ cp config.json.tmp config.json
+ rm config.json.tmp
fi
We also encountered this problem for kubernetes v1.20. Instead of mounting config.json, we mount .docker directory. In this way, you can change config.json (rewrite, replace, etc.) in container environment.
duplicate https://github.com/scality/cloudserver/issues/1520#issuecomment-419576769