【发布时间】: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
pwd 和ls 确认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