dockeropenssldockerfiledocker-buildbuildx

how to use Dockerfile to install openssl?


I am creating a docker image for an application that required OpenSSL 1.1.1 instead of the default 3.0

I added the following command in the Dockerfile

RUN wget -O - https://www.openssl.org/source/openssl-1.1.1u.tar.gz | tar zxf -
RUN cd openssl-1.1.1u 
RUN ./config --prefix=/usr/local

However, the line RUN ./config --prefix=/usr/local throw the following error during building the image.

Error: buildx failed with: ERROR: failed to solve: process "/bin/sh -c ./config --prefix=/usr/local" did not complete successfully: exit code: 127

How can I fix this error?


Solution

  • Each RUN command is separate, so the cd doesn't persist across them; you'll need to do something like:

    RUN wget -O - https://www.openssl.org/source/openssl-1.1.1u.tar.gz | tar zxf -
    RUN cd openssl-1.1.1u; ./config --prefix=/usr/local
    

    In addition, each RUN command creates a new layer in the resulting docker image; if you want to end up with slim images, and especially if you want to clean up files, you may want to combine them even further:

    RUN wget -O - https://www.openssl.org/source/openssl-1.1.1u.tar.gz | tar zxf -; \
        cd openssl-1.1.1u; \
        ./config --prefix=/usr/local
    

    (cleaning up files only really removes them if it's done in the same layer; otherwise, the files are still there, just marked as deleted)