Home > other >  Docker - how to create an empty file in a temporary container?
Docker - how to create an empty file in a temporary container?

Time:03-24

How to create a scratch in the Dockerfile container empty file?
Try 1
Obviously, the touch is not available:

The FROM scratch
The RUN [" touch ", ". Emptyfile "]

Results:

Container_linux. Go: 265: starting the container process under caused "exec: " touch \ ": the executable file not found in $PATH"

Try 2
Unfortunately, nor use/dev/null:

The FROM scratch
COPY/dev/null. Emptyfile

Results:

COPY failed: stat/var/lib/docker/TMP/docker - builder872453691/dev/null: no to the file or directory

I can in the Docker host build context to create an empty file and then copy it, but you know, it's too easy.
If you have any idea?

CodePudding user response:

No command to run. The only option is to COPY, and ADD you to start from scratch. And you can COPY or ADD files from the context (unless you want to remote URL from I don't recommend ADD). Therefore, you need to create an empty file on the context and COPY it.
Then docker introduced multi-stage build, let you use another building as your context. Therefore, you can create an empty file in one stage and copy it to another stage.

The FROM busybox AS build - env
The RUN touch/empty

The FROM scratch
COPY - from=build - env/empty/. Emptyfile

CodePudding user response:

SillyB
  • Related