Reputation: 337
I'm working on a dockerfile for the meganz cmd utility.
I have set environment variables for the login command and it works as intended on my private builds, with a legit username and password.
I am making a public build using dockerhub and I populate the environment variables with default values and it causes the automatic build to fail in DockerHub.
Is it possible to ignore this specific error during the build so it passes? I fully expect this command to fail with default credentials.
RUN mega-login ${email} ${password}
The command '/bin/sh -c mega-login ${email} ${password}' returned a non-zero code: 13
Upvotes: 4
Views: 7126
Reputation: 31584
You could use ||
to bypass the exit code. Something like next:
Old Dockerfile:
FROM ubuntu:16.04
RUN lll
RUN pwd
Old execution:
$ docker build -t abc:1 .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM ubuntu:16.04
---> 065cf14a189c
Step 2/3 : RUN lll
---> Running in b7f9a2fd7f6d
/bin/sh: 1: lll: not found
The command '/bin/sh -c lll' returned a non-zero code: 127
New Dockerfile:
FROM ubuntu:16.04
RUN lll || :
RUN pwd
New execution:
$ docker build -t abc:1 .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM ubuntu:16.04
---> 065cf14a189c
Step 2/3 : RUN lll || :
---> Running in 9a0b3ebea003
/bin/sh: 1: lll: not found
Removing intermediate container 9a0b3ebea003
---> af76014cf9aa
Step 3/3 : RUN pwd
---> Running in a4766055c81e
/
Removing intermediate container a4766055c81e
---> c82c077ed8ea
Successfully built c82c077ed8ea
Successfully tagged abc:1
Explain for cmd1 || cmd2
:
If cmd1
exit code is zero, the cmd2
will not execute, if cmd1
exit code is non-zero, the cmd2
will run. Here, :
means a empty command which will result in zero exit code, then it will cheat docker build to let it not exit.
So, for you it could be:
RUN mega-login ${email} ${password} || :
Upvotes: 9