“ELF:not found”和“语法错误:未预料到”(“\”“在Docker容器中

时间:2017-12-01 19:16:34

标签: linux docker

我正在尝试为beanstalkd-cli构建Docker镜像。图像构建成功,但是当我运行docker run -it myimage时,它失败了:

/usr/local/bin/beanstalkd-cli: line 1: ELF: not found
/usr/local/bin/beanstalkd-cli: line 2: syntax error: unexpected "("

这是否意味着构建不好?或者我是否需要调整ENTRYPOINT和/或CMD

这是我的Dockerfile:

FROM alpine:3.5

LABEL maintainer="Coby Tamayo <ctamayo@sitecrafting.com"

# Install openssl, beanstalkd-cli
RUN apk add --update openssl && \
  wget https://github.com/schickling/beanstalkd-cli/releases/download/0.3.0/beanstalkd-cli-linux.tar.gz && \
  tar -xvzf beanstalkd-cli-linux.tar.gz && \
  chmod +x beanstalkd-cli && \
  mv beanstalkd-cli /usr/local/bin/beanstalkd-cli && \
  rm beanstalkd-cli-linux.tar.gz

ENTRYPOINT ["/bin/sh"]
CMD ["/usr/local/bin/beanstalkd-cli"]

更新1

当我完全删除ENTRYPOINTCMD时,运行容器会将我放入shell中,我可以在其中验证beanstalkd-cli是否设置了执行权限:

$ docker run -it myimage
/ # which beanstalkd-cli
/usr/local/bin/beanstalkd-cli
/ # ls -la /usr/local/bin/beanstalkd-cli
-rwxrwxr-x    1 1000     1000       3020529 Feb 23  2015 /usr/local/bin/beanstalkd-cli

只是“为了好玩”,我也尝试只设置ENTRYPOINT,没有命令,因为我真的不关心在这个容器中运行除beanstalkd-cli命令之外的任何东西:

ENTRYPOINT ["/usr/local/bin/beanstalkd-cli"]
# no more CMD

当我docker run 这个时,我得到:

standard_init_linux.go:185: exec user process caused "no such file or directory"

如果我重新添加原始CMD,结果相同。嗯?

更新2

# file /usr/local/bin/beanstalkd-cli
/usr/local/bin/beanstalkd-cli: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=63a19b18574643c1da5bafd5bd56fc26af22ab05, not stripped

# uname -a
Linux 6882ec36481d 4.10.0-40-generic #44~16.04.1-Ubuntu SMP Thu Nov 9 15:37:44 UTC 2017 x86_64 Linux

# /usr/local/bin/beanstalkd-cli
/bin/sh: /usr/local/bin/beanstalkd-cli: not found

1 个答案:

答案 0 :(得分:3)

诊断问题

使用您的Dockerfile:

docker run 04d32bac400e '-xlic' 'ldd /usr/local/bin/beanstalkd-cli'

...发射:

+ ldd /usr/local/bin/beanstalkd-cli
    /lib64/ld-linux-x86-64.so.2 (0x7f9044206000)
    libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f9044206000)
    libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f9044206000)
    librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7f9044206000)
    libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f9044206000)
    libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f9044206000)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /usr/local/bin/beanstalkd-cli)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/local/bin/beanstalkd-cli)
Error relocating /usr/local/bin/beanstalkd-cli: __gcc_personality_v0: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: __register_atfork: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: __rawmemchr: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: _Unwind_DeleteException: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: _Unwind_RaiseException: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: _Unwind_FindEnclosingFunction: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: _Unwind_GetIP: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: _Unwind_Backtrace: symbol not found
Error relocating /usr/local/bin/beanstalkd-cli: _Unwind_Resume: symbol not found

所以 - 您使用的beanstalkd库与libgcc_s.so.1ld-linux-x86-64.so.2相关联,而这两个库都不是由Alpine 3.5基本图像提供的;因此,&#34;没有这样的文件或目录&#34;尝试运行可执行文件时。

简易解决方案

考虑较重的基本图像;例如,以下内容正常工作:

FROM ubuntu:16.04

LABEL maintainer="Coby Tamayo <ctamayo@sitecrafting.com>"

# Install openssl, beanstalkd-cli
RUN apt-get update
RUN apt-get install -y wget
RUN wget https://github.com/schickling/beanstalkd-cli/releases/download/0.3.0/beanstalkd-cli-linux.tar.gz && \
  tar -xvzf beanstalkd-cli-linux.tar.gz && \
  chmod +x beanstalkd-cli && \
  mv beanstalkd-cli /usr/local/bin/beanstalkd-cli && \
  rm beanstalkd-cli-linux.tar.gz

CMD ["/usr/local/bin/beanstalkd-cli"]