This is because Docker loads the entire directory context (where your Docker file is located) to the Docker daemon at the beginning. From Docker Docs
The build is done by the Docker daemon, not the CLI. The first thing the build process does is send the entire context (recursively) to the daemon. In most cases, it is best to start with an empty directory as context and store the Docker file in this directory. Add only the files needed to create the Docker file.
Since your text file was not available at the beginning, you will receive this error message. If you still want the text file to be added to the Docker image, you can invoke the docker build command from the same script file. Modify script.sh,
#!/usr/bin/env bash printf "blah blah blah blah\n" | sudo tee <docker-file-directory>/file.txt docker build --tag yourtag <docker-file-directory>
And modify your Docker file just to add the generated text file.
ADD file.txt .. <rest of the Dockerfile instructions>
source share