添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Docker image with Alpine Linux: an executable file is definitely there but cannot be found while trying to execute

Ask Question

Here is the output of my terminal, while I am inside the shell of a Docker container with an Alpine image:

bash-5.0# ls
makeThumb
bash-5.0# ./makeThumb 
bash: ./makeThumb: No such file or directory
bash-5.0# 

As you can see, I have an executable file called makeThumb, and it is definitely there (see the output of ls). However, it is strange that when I'm trying to execute it with ./makeThumb it says No such file or directory.

How to solve this?

My Dockerfile:

FROM mhart/alpine-node:14 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
FROM mhart/alpine-node:14
RUN apk update && apk add bash
COPY --from=build /app/ /app/
WORKDIR /app
RUN npm prune --production
EXPOSE 3000
CMD [ "node", "server.js" ]

Output of ldd makeThumb:

ldd makeThumb 
    /lib64/ld-linux-x86-64.so.2 (0x7f0c421ae000)
    libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f0c421ae000)
    libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f0c421ae000)
    librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7f0c421ae000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f0c42015000)
    libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0c421ae000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f0c42001000)
    libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0c421ae000)
Error relocating makeThumb: __strdup: symbol not found
Error relocating makeThumb: __vfprintf_chk: symbol not found
Error relocating makeThumb: __sprintf_chk: symbol not found
Error relocating makeThumb: __snprintf_chk: symbol not found
Error relocating makeThumb: __vsnprintf_chk: symbol not found
Error relocating makeThumb: __strcat_chk: symbol not found
Error relocating makeThumb: __memset_chk: symbol not found
Error relocating makeThumb: __fprintf_chk: symbol not found
Error relocating makeThumb: __memcpy_chk: symbol not found
Error relocating makeThumb: __longjmp_chk: symbol not found
                Can you include your image's Dockerfile?  Are you correctly copying the PNG file you attached into the image; COPY j27cg.png .?  Where does the makeThumb binary come from, and how is this PNG file related to it?
– David Maze
                May 24, 2021 at 12:56
                @DavidMaze Included the Dockerfile. This PNG file j27cg.png does not relate to the Docker image in any way. It is just a screenshot
– Azamat Abdullaev
                May 24, 2021 at 13:01
                Could be that the makeThumb program is compiled to target another architecture than the one you are using. Can you post the result from file makeThumb and uname -a ?
– ShellCode
                May 24, 2021 at 13:02
                Can you post the output of ldd makeThumb ? It could be a missing dependency. EDIT: actually, don't post it, just make sure all the dependencies are met ;)
– ShellCode
                May 24, 2021 at 13:07

Alpine makes use of musl which is a minimalistic libc. My guess is that your binary is using non-standard functions that do not exist under Alpine.

I see two solutions to that :

  • Try to install glibc in your docker container
  • Probably the easiest solution : try to find a Docker image that uses it as default (a minimalistic Debian/Ubuntu Docker should do it)
  • The 2nd solution helped, just the image size got a little larger, and that's not a big problem for me. Thanks – Azamat Abdullaev May 24, 2021 at 15:28

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.