For a quick test image I don’t want to create a folder and a file. Docker can read the Dockerfile from standard input, and a here-document makes it a one-command experiment.
docker build -t myimage:latest - <<EOF
FROM busybox
RUN echo "hello world"
EOF
With - as the context there is no build context at all, which the docs call an empty context. You can also pipe a file in with docker build - < Dockerfile.
If the Dockerfile needs local files, give it a context and read only the Dockerfile from stdin with -f-:
docker build -t myimage:latest -f- . <<EOF
FROM busybox
COPY somefile.txt ./
RUN cat /somefile.txt
EOF
Here the current directory is the context, so COPY somefile.txt works. The docs also show a remote context, docker build -f- <URL> with a Git repository, and building directly from the URL of a remote Dockerfile.
The caveat is the first form. Without a filesystem context, instructions like COPY cannot refer to local files, so that build fails. Use -f- . when you need your files. I’d also keep anything long in a real file in version control, because a here-document in shell history is a poor place to store a recipe.
Further reading: Docker build context