Problem: returned a non-zero code: 1
It can be a bit frustrating to see the following Docker error:
The command ‘/bin/sh -c rm /etc/nginx/conf.d/default.conf’ returned a non-zero code: 1
Solution: ;exit 0
However if you find yourself stalled out with this error, you might try converting this into a warning by adding ‘; exit 0’ to the end of your RUN command:
In this example we don’t care about a docker error for a non-zero return in subsequent builds. Make sure that before you do this, you understand what it is you are ignoring and if there is not a deeper underlying problem.
FROM nginx:latest # Remove default configuration files RUN rm /etc/nginx/conf.d/default.conf; exit 0 # Copy our custom config files to Nginx Contatiner COPY nginx.conf /etc/nginx COPY site.conf /etc/nginx/conf.d
Now when we build we still see the warning, but the Docker build continues:
[user@computer project]$ docker build -t nginx nginx Sending build context to Docker daemon 5.632kB Step 1/4 : FROM nginx:latest ---> 0c3656469914 Step 2/4 : RUN rm /etc/nginx/conf.d/default.conf; exit 0 ---> Running in 2cc792ecba71 rm: cannot remove '/etc/nginx/conf.d/default.conf': No such file or directory ---> 8127ca93feba Removing intermediate container 2cc792ecba71 Step 3/4 : COPY nginx.conf /etc/nginx ---> 27799064636b Removing intermediate container 1ff675e77a27 Step 4/4 : COPY site.conf /etc/nginx/conf.d ---> b36c3bce3498 Removing intermediate container fb7f2970fbf6 Successfully built b36c3bce3498 Successfully tagged nginx:latest
The world is right, time for a happy dance!