【问题标题】:Dockerfile ENTRYPOINT script: "No such file or directory" on existing fileDockerfile ENTRYPOINT 脚本:现有文件上的“没有这样的文件或目录”
【发布时间】:2026-01-31 04:10:01
【问题描述】:

我编写了一个 Dockerfile,目的是在 Docker 容器中托管游戏服务器,但是复制到容器中的 shell 脚本(“run.sh”)看不到它的 ELF 可执行文件应该运行。

我已配置我的 Dockerfile,使其使用最新版本的 ubuntu 软件包,下载游戏服务器的文件并将其解压缩到新文件夹,然后删除 .zip 存档。它成功构建,但是当我尝试使用由三行组成的简单 shell 脚本运行它时:

run.sh

#!/usr/bin/env bash
pwd
ls
exec ./TerrariaServer.bin.x86 -steam -config ./config.txt

它总是出现以下错误:./run.sh: line 4: /ServerFiles/TerrariaServer.bin.x86: No such file or directory

pwdls 确认TerrariaServer.bin.x86 存在于/ServerFiles/ 目录中:

/ServerFiles
FNA.dll
FNA.dll.config
Mono.Posix.dll
Mono.Security.dll
System.Configuration.dll
System.Core.dll
System.Data.dll
System.Drawing.dll
System.Numerics.dll
System.Runtime.Serialization.dll
System.Security.dll
System.Windows.Forms.dll
System.Windows.Forms.dll.config
System.Xml.Linq.dll
System.Xml.dll
System.dll
Terraria.png
TerrariaServer
--> TerrariaServer.bin.x86 <--
TerrariaServer.bin.x86_64
TerrariaServer.exe
WindowsBase.dll
changelog.txt
config.txt
lib
lib64
monoconfig
monomachineconfig
mscorlib.dll
open-folder
run.sh

我在 * 上看到的其他答案都指出了权限冲突(我出于测试目的大量应用了 chmod 777)和 Windows 行尾(Dockerfile 和 run.sh 都是通过纳米通过 PuTTY 创建和编辑的) ,但我所做的任何更改似乎都不会影响结果。

Dockerfile

FROM  ubuntu:latest

# Get wget package
RUN  apt-get update \
  && apt-get install -y wget \
  && apt-get install -y unzip \
  && rm -rf /var/lib/apt/lists/*

#RUN  apt-get install dos2unix

# Download and extract Terraria server files
RUN  pwd \
  && mkdir Downloads

RUN  cd Downloads \
  && wget -O "/Downloads/TServer.zip" http://terraria.org/server/terraria-server-1353.zip \
  && ls
RUN  unzip "/Downloads/TServer.zip" -d "/Downloads/TServer/"

# Extract the linux folder and delete old files/folders
RUN  cp -ra "/Downloads/TServer/1353/Linux/" "/ServerFiles/" \
  && rm -rf "/Downloads/TServer.zip" \
  && rm -rf "/Downloads/TServer/"

COPY run.sh /ServerFiles/run.sh
RUN chmod 777 /ServerFiles/run.sh

# Set the working directory
WORKDIR  "/ServerFiles/"
RUN ls
RUN chmod 777 .

RUN  chmod 777 TerrariaServer.bin.x86
RUN  adduser --disabled-password --gecos '' tserveruser \
  && adduser tserveruser sudo
RUN  chown -R tserveruser:tserveruser /ServerFiles
RUN  chown tserveruser:tserveruser /ServerFiles/TerrariaServer
USER  tserveruser

# Create the default config.txt
RUN printf "maxplayers=8\nport=7777\npassword=testpass\nworldpath=~/ServerFiles/Worlds/\ndifficulty=0\nautocreate=2\nworldname=World" \
  > config.txt

ENTRYPOINT ["./run.sh"]

【问题讨论】:

    标签: docker dockerfile ubuntu-server


    【解决方案1】:

    在黑暗中刺伤...我能想到的唯一一件事可以解释您所看到的行为,因为您提供了如此出色的所有数据...

    /ServerFiles/TerrariaServer.bin.x86 是否可能是一个未指向现有文件的符号链接?这将产生您显示的列表和尝试运行该“文件”时遇到的错误。也可能是它指向一个没有适当权限的文件。

    如果不是这样,也许你应该做一个“ls -l”来看看这是否能提供任何线索。

    【讨论】:

      【解决方案2】:

      对于您已确认存在的二进制文件,此错误通常意味着您有动态链接的库,但该库不存在于映像中。使用 shell 运行您的图像,然后从那里检查 ldd /ServerFiles/TerrariaServer.bin.x86 以查看预期和可能缺少的库。

      【讨论】:

      • 这不会产生不同的错误吗?它不会抱怨缺少库而不是提及基本可执行文件本身吗? - 我也不是 100% 确定我的答案,但它很容易测试,所以我做到了。我试图思考如何轻松测试这个假设。不是说你不对。我只是不会猜到这是给定错误消息的潜在原因。我喜欢学习新事物,尤其是在像这样会让一个人发疯的领域。
      • @Steve 不幸来自 Linux 内核,或者可能是动态链接代码,它是完全相同的错误消息。过去,很多将代码放入 docker 的人都经历过。以至于它做了我的常见问题演示:sudo-bmitch.github.io/presentations/dc2018/…
      最近更新 更多