Dockerfile 入口点脚本 : "No such file or directory" on existing file

标签 docker dockerfile ubuntu-server

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

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

运行.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 directorypwdls确认 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

我在 StackOverflow 上看到的其他答案指出了权限冲突(我出于测试目的大量应用了 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"]

最佳答案

黑暗中的刺伤......我能想到的唯一一件事就是解释你所看到的行为,因为你已经很好地制作和提供了所有数据......

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

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

关于Dockerfile 入口点脚本 : "No such file or directory" on existing file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55329292/

相关文章:

regex - BASH_REMATCH 在正则表达式匹配后显示空字符串

linux - Linux 中的 "blk_update_request"是什么?

ruby - 从 Docker 容器登录到 macOS 中的系统日志/控制台?

mysql - 如何从主机连接 MySQL Docker 镜像?

linux - 删除了根目录的读取和执行权限

Docker Compose 开发和生产环境最佳工作流程

visual-studio - 在Visual Studio 2019中进行调试时,Dockerfile似乎没有运行

docker - 可以看到 Docker 容器中的文件,但无法访问它

docker - 如何访问另一个容器的Docker日志

docker - 运行命令来创建新的 Docker 容器