Moving then executing script in Dockerfile causes "Text file busy" error


I have a Dockerfile that moves a script, then executes the destination script. The move command seems to be uncompleted by the time of the execution command, causing a “Text file busy” error.

This is unexpected behaviour because mv /dir1 && /dir1/ seems like a very simple sequence of commands. I have this in another Dockerfile and it was failing on 9 out of 10 builds.

I’ve created a simple Dockerfile to reproduce this issue: .

The build log showing this error is below. is just a dummy script that sleeps for 30s. The full log is on .

Step 3/3 : RUN mkdir /dir1 && mv / /dir1 && /dir1/
 ---> Running in f8c19e91fed4
/bin/sh: 1: /dir1/ Text file busy
The command '/bin/sh -c mkdir /dir1 && mv / /dir1 && 
  /dir1/' returned a non-zero code: 2
Exited with code 2

Feel free to keep rebuilding to reproduce the error.



If I make it sleep and wait for the mv command to complete before executing the script, the error is fixed. E.g. mkdir /dir1 && mv / /dir1 && sleep 5s && /dir1/

The modified Dockerfile with additional sleep command:

After making this modification, the build succeeds on .

This fix is weird though and shouldn’t be necessary to fix a simple command like this.