我是 docker 新手.我想容器一个小环境,这样我就可以运行可执行文件,但我被困住了,因为我甚至无法运行可执行文件.
我的文件夹 struct 如下所示:
example/
|-Dockerfile
|-hello_world
我的Dockerfile
看起来是这样的:
# Use Alpine Linux as the base image
FROM alpine:latest
# Set the working directory inside the container
WORKDIR /app
# Copy the executable to the container
COPY hello_world /app/
# Set the permissions for the executable
RUN chmod +x /app/hello_world
# Define the command to run your server when the container starts
ENTRYPOINT ["/app/hello_world"]
然后我跑:
> sudo docker build -t example .
个
> sudo docker run --name example_container example
其结果是:
exec /app/hello_world: no such file or directory
个
我已经try 了尽可能多的变体,试图在Dockerfile中使用CMD
、RUN
和ENTRYPOINT
,但都有相同的结果,即在根目录下的app文件夹中找不到Hello_world程序.
我真的很困惑,因为我在我的香草Ubuntu操作系统上try 了这一点,我在根目录下放了一个测试文件夹,然后在那里放了一个hello_world
,似乎可以很好地从任何地方使用这个绝对路径运行它.
/app/hello_world
是一个可执行文件,它是一段编译过的Rust代码.当我在我的Ubuntu机器上运行/app/hello_world
个shell 时,它运行得很好.
稳定-x86_64-未知-linux-gnu工具链/rustc 1.71.0
有人能告诉我我做错了什么吗?