15

Here is My Docker File:

FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install libssl-dev

RUN apt-get install -y -q build-essential curl
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /command-agent
COPY . /command-agent
RUN cargo build --release
COPY /command-agent/target/release/command-agent /
EXPOSE 8080
ENTRYPOINT command-agent

Its build successfully docker image but when i run that container its gives error:

command-agent: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /command-agent/command-agent)

I do not understand, How can i fix this issue ?

Jahadul Rakib
  • 476
  • 1
  • 5
  • 19
  • 2
    Means exactly what it says -- you're not running against the same libc that compilation was against. Be sure you compile executables on the same platform you're going to run them on unless you're going to make sure they're static. – Charles Duffy Apr 15 '22 at 16:23
  • no sir, when i run the binary in my ubuntu machine...its working fine....in my application i use kafka and actix-web.....but docker container giving this error – Jahadul Rakib Apr 15 '22 at 16:27
  • 1
    Right, but which _version_ of Ubuntu is your container running, vs which version is your working host running? Specifically, you need to compare the libc releases between them. – Charles Duffy Apr 15 '22 at 16:28
  • Distributor ID: Ubuntu Description: Ubuntu 21.10 Release: 21.10 Codename: impish – Jahadul Rakib Apr 15 '22 at 16:29
  • 1
    Ask your package manager (I haven't used Ubuntu in long enough I don't remember dpkg commands) which package provides your `libc.so.6`, _including_ the exact version number, on both machines. – Charles Duffy Apr 15 '22 at 16:30
  • 1
    You can also use `objdump` or `nm` to look at the specific symbols exported by each library. – Charles Duffy Apr 15 '22 at 16:31
  • thanks sir...i inform you after applying your instruction – Jahadul Rakib Apr 15 '22 at 16:33
  • 1
    BTW, is there any chance that what you're `COPY`ing in already has precompiled executables (or shared objects from a partial compilation) inside it, so the `RUN cargo build --release` is leaving them alone instead of replacing them? I haven't seen this error in the Rust world with any frequency, but it's the kind of thing I saw _all the time_ doing porting/packaging work in C, when someone bundled up a "source tarball" that hadn't been `make clean`ed first. – Charles Duffy Apr 15 '22 at 16:35
  • i also make file by copying binary file...but thats giving me same error – Jahadul Rakib Apr 15 '22 at 16:39
  • 2
    @CharlesDuffy has a good point. Unless you have a `.dockerignore` file set up correctly, the `target` directory will also be copied, and then the `cargo build` command will not actually rebuild if you have already run the build locally. – Herohtar Apr 15 '22 at 16:39
  • Ok, let me set up a .dockerignore file – Jahadul Rakib Apr 15 '22 at 16:42
  • 2
    To be clear / explicit, you want to be sure the `target/` directory is ignored during the COPY. – Charles Duffy Apr 15 '22 at 16:46
  • sure sir, i inform you after applying – Jahadul Rakib Apr 15 '22 at 16:48
  • @Charles Duffy sir....thanks a lot sir, its working now for me to avoid target dir ... after then modify some entry point. your instruction giving me some important concept. please take my respect to you sir – Jahadul Rakib Apr 15 '22 at 19:02
  • @Herohtar sir, thanks a lot for your quick response and help me understand possible problem scope. please take my respect to you. thanks again sir. – Jahadul Rakib Apr 15 '22 at 19:03

1 Answers1

5

ITs works for me when i avoid /target directory and now working both version of ubuntu 20.04 and 21.10. Giving thanks to @Charles Duffy and @Herohtar for their important and useful instruction,

FROM ubuntu:21.10
RUN apt-get update && apt-get upgrade -y
RUN apt-get install libssl-dev

RUN apt-get install -y -q build-essential curl
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /command-agent
COPY ./src/. /command-agent/src/
COPY .env /command-agent/
COPY Cargo.toml /command-agent/
COPY Cargo.lock /command-agent/
RUN cargo build --release

EXPOSE 8080
ENTRYPOINT /command-agent/target/release/command-agent
smoore4
  • 4,520
  • 3
  • 36
  • 55
Jahadul Rakib
  • 476
  • 1
  • 5
  • 19