peez80
peez80

Reputation: 1643

Why does the build in this dockerfile fail, while exact the same commands run manually succeed?

I'm trying to build the following Dockerfile:

FROM ubuntu:focal

RUN ln -snf /usr/share/zoneinfo/Europe/Berlin /etc/localtime && echo Europe/Berlin > /etc/timezone \
&& apt-get update \
&& apt-get install -y git default-jdk-headless ant libcommons-lang3-java libbcprov-java \
&& git clone https://gitlab.com/pdftk-java/pdftk.git \
&& cd pdftk \
&& mkdir lib \
&& ln -st lib /usr/share/java/{commons-lang3,bcprov}.jar \
&& ant jar

CMD ["java", "-jar", "/pdftk/build/jar/pdftk.jar"]

When building the image, it fails upon the ant step with several errors like this:

[javac]   symbol:   class ASN1Sequence
[javac]   location: class PdfPKCS7
[javac] /pdftk/java/pdftk/com/lowagie/text/pdf/PdfPKCS7.java:282: error: cannot find symbol
[javac]         BigInteger serialNumber = ((ASN1Integer)issuerAndSerialNumber.getObjectAt(1)).getValue();

However when starting a container manually (docker run -it --rm ubuntu:focal) and executing exact the same commands (Sure no typo, Copy/Pasted the whole block several times), the build succeeds.

Any idea what might be different during the docker build and a manually started container?

Upvotes: 2

Views: 247

Answers (1)

Eranga Heshan
Eranga Heshan

Reputation: 5804

Wow, this one is a tricky one. 🔎

When you build the container, the program which executes your instruction set is shell (/bin/sh) whereas when you run docker run -it --rm ubuntu:focal, it is going to be run on bash (/bin/bash).

Basically, you manually ran all your instructions on bash.

The easiest solution would be to use bash to run your instruction set because it already works as you tested.

You can simply instruct the docker to run all your instructions on bash using this command at the top:

SHELL ["/bin/bash", "-c"]

The changed Dockerfile will be:

FROM ubuntu:focal

SHELL ["/bin/bash", "-c"]

RUN ps -p $$
RUN ln -snf /usr/share/zoneinfo/Europe/Berlin /etc/localtime && echo Europe/Berlin > /etc/timezone \
&& apt-get update \
&& apt-get install -y git default-jdk-headless ant libcommons-lang3-java libbcprov-java \
&& git clone https://gitlab.com/pdftk-java/pdftk.git \
&& cd pdftk \
&& mkdir lib \
&& ln -st lib /usr/share/java/{commons-lang3,bcprov}.jar \
&& ant jar

CMD ["java", "-jar", "/pdftk/build/jar/pdftk.jar"]

Hope this helps you. Cheers 🍻 !!!

Upvotes: 3

Related Questions