Ann
Ann

Reputation: 473

Shell script failing on mkdir in Dockerfile

Have a Shell script as follows

ENV HOME=/home
RUN mkdir $HOME

Above script is in a Docker file and getting exception as follows [91mmkdir: missing operand Try 'mkdir --help' for more information. Build step 'Docker Build and Publish' marked build as failure

Upvotes: 0

Views: 1335

Answers (1)

queeg
queeg

Reputation: 9463

I just tried with a Dockerfile like this:

FROM scratch
ENV HOME=/home
RUN mkdir $HOME

and got that:

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM scratch
 ---> 
Step 2/3 : ENV HOME=/home
 ---> Running in e9d03ee00aa7
Removing intermediate container e9d03ee00aa7
 ---> 16f6e2ba2f09
Step 3/3 : RUN mkdir $HOME
 ---> Running in 6847b9b34717
failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory: unknown
$

Then I edited the file to look like this:

FROM mariadb
ENV HOME=/home
RUN mkdir $HOME

and got that:

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM mariadb
 ---> ea81af801379
Step 2/3 : ENV HOME=/home
 ---> Running in 7d903215da74
Removing intermediate container 7d903215da74
 ---> 77276b970083
Step 3/3 : RUN mkdir $HOME
 ---> Running in f120f966144f
mkdir: cannot create directory '/home': File exists
The command '/bin/sh -c mkdir $HOME' returned a non-zero code: 1
$

From the error message I can see the $HOME variable would not have been an issue. It should have worked on your side as well.

Upvotes: 1

Related Questions