1

I am trying to create a simple docker image on top of a Ubuntu base image.

I have a small server program (single executable file) built by g++. The program uses openssl and it works well in my Ubuntu.

Now I want to put the program in a docker image and run it by docker, because I am learning docker.

I used the following Dockerfile:

FROM ubuntu
ARG APPDIR=/usr/local/myserver
WORKDIR ${APPDIR}

# copy my single server program file
COPY build/bin/svr ./

# install openssl into the image
RUN apt-get -y update
RUN apt-get -y install openssl
#RUN apt-get -y install libssl-dev

# run the server program
EXPOSE 1080
EXPOSE 1443
CMD ./svr

No matter I install openssl or libssl-dev, the docker image just failed to run with the following error:

./svr: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

I googled a lot with no luck. How can I fix this? Thanks!!


I found out that the "libssl.so.1.1" that my program is referencing is missing from the docker image. I used "CMD find /usr -name libssl*" to check what ssl dlls are available in the image and it turned out only the "libssl3.so" is in the image.

I am using Ubuntu 20 and I installed the openssl sdk by "apt install libssl-dev". It seems the sdk is only for v1.1... The problem is that, on Ubuntu, if you do "apt install libssl-dev", you get the sdk for 1.1 and if you do "apt install openssl", you get libssl3.so.

I know I can manually copy the .so.1.1 into my docker image instead of running apt-get, but I don't think it to be a graceful approach.

Zhou
  • 633
  • 5
  • 16
  • Is it exactly the same version as on the machine you compile the executable with? Most likely it’s installing a different version. – Sami Kuhmonen Mar 16 '23 at 18:33
  • In particular probably 'my Ubuntu' is slightly older; `ubuntu:latest` in dockerhub is 22.04 'jammy' which has OpenSSL at 3.0.2 which is libssl.so.3 not libssl.so.1.1 as in earlier versions. PS: to only run you don't need libssl-dev, libssl3 (or libssl1.1 as applicable) is sufficient. – dave_thompson_085 Mar 16 '23 at 20:21
  • @SamiKuhmonen you are right. I added some additional info to my post. but I can't find a graceful way to solve the problem. – Zhou Mar 17 '23 at 09:26
  • @dave_thompson_085 as you suggested, I tried to do "RUN apt-get -y install libssl1.1" but the apt-get failed to work. It's wired. "sudo apt-get install libssl1.1" worked well in my Ubuntu but it didn't work for the docker image. I think I'm too new to docker so I must've misunderstood some things. – Zhou Mar 17 '23 at 09:36
  • 1
    The simplest way would be to use the exact same OS version and packages on both compilation system and image. That might be simple to do by running the build in an image also, or just selecting the correct version as the base image. – Sami Kuhmonen Mar 17 '23 at 13:25
  • 1
    You can replace first line in the Dockerfile with `FROM ubuntu:20.04` to use Ubuntu 20.04 as base image – eltio Mar 17 '23 at 18:16
  • 1
    I didn't say to install 1.1; I said the ubuntu you are getting in docker -- currently 22.04 -- does not support 1.1. Installing _either_ libssl-dev _or_ openssl _on 22.04_ gets libssl3, while on your 20(.04?) dev system both get 1.1. Manually copying things that don't match the package manager is indeed clumsy, and in general unsafe. As Sami and @eltio say the correct solution is to run on the same Ubuntu version you build on. If you can't, an alternative is to build with static linking; that should give an executable that runs on any nonancient Ubuntu and even most(?) other Linux. – dave_thompson_085 Mar 17 '23 at 18:52
  • @SamiKuhmonen Thanks for the suggestion. I will try running the build in the image (as I interpret it, I should issue the build command by a RUN statement in my Dockerfile). – Zhou Mar 20 '23 at 13:26
  • @dave_thompson_085 Thanks. I will try both approaches --- 1. run the build in the image, 2. don't run the build but base my image on the same Ubuntu as my working machine. – Zhou Mar 20 '23 at 13:29

1 Answers1

1

I was having this problem as well. It was puzzling because initially I was running my project using the rust Docker image right after building it in the same image. When I switched to a builder pattern, I was using the ubuntu image as my runner image and was unable to locate a suitable package providing this library.

I dug around and found out that the rust image is based on the debian image and in the first layer installs the libssl1.1 package using APT. Replicating this solved my problem:

FROM debian:latest

# make sure libssl.so.1.1 is available
RUN apt-get update && apt-get install -y libssl1.1 && apt clean && rm -rf /var/lib/apt/lists/*

... # copy / run project
Campbell Cole
  • 37
  • 1
  • 9
  • You are using `debian` as the base, so that's a different story. The root cause of my problem was I used `ubuntu` so docker based my image on the latest ubuntu, but the latest version no longer supports `libssl 1.1`, so if I do `apt install libssl`, it will install `libssl3`; if I do `apt install libssl1.1` (as you suggested), it will fail with "Unable to locate package libssl1.1". I finally resolved my problem by `FROM ubuntu:20.04`. Anyway, thank you very much for your answer! – Zhou Apr 12 '23 at 16:28