Docker 容器在运行挂载本地文件的 makefile 时找不到文件。如何排除故障?

问题描述 投票:0回答:0

我想创建一个 makefile 来运行编译后的 C 文件,给定另一个文件并在 Docker 映像中输入。我尝试挂载本地文件作为容器内的参数,但是当我执行

make run IMAGE=<img> FILE=<local file> INPUT=<input>
:

时出现以下错误
docker: Error response from daemon: failed to create shim task: OCI runtime create
failed: runc create failed: unable to start container process: exec:
"/app/folder/build/compiledFile": stat /app/folder/build/compiledFile: no such file or directory: unknown.

我不明白为什么容器找不到“compiledFile”,因为当我用 Docker Desktop 查看容器内部时,“compiledFile”确实存在。当我在没有参数和默认变量值的情况下运行 make run 时,一切正常。

这是 Docker 文件

FROM ubuntu:latest

WORKDIR /app

RUN apt-get update && \
    apt-get install -y \
        cmake \
        make \
        gcc \
        git

RUN git clone https://url.com

COPY file /app/folder/file

WORKDIR /app/folder

RUN mkdir build && cd build && cmake .. && make

ENTRYPOINT ["/app/folder/build/compiledFile"]

# Runs file on compiledFiled with 0000 by default
CMD ["/app/folder/file", "0000"]

和生成文件:

hubimg=myimage

IMAGE ?= myimage
INPUT ?= 0000

ifdef FILE
DOCKER_RUN_COMMAND = docker run -v $(dir $(abspath $(FILE))):/app/folder $(IMAGE) /app/folder/$(notdir $(FILE)) $(INPUT)
else
DOCKER_RUN_COMMAND = docker run $(IMAGE) $(INPUT)
endif

build:
    docker build -t $(IMAGE) .

run:
    $(DOCKER_RUN_COMMAND)

pull:
    docker pull $(hubimg)
    docker tag $(hubimg) $(IMAGE)

dockerhub:
    echo $(hubimg)
docker cmake makefile dockerfile
© www.soinside.com 2019 - 2024. All rights reserved.