简体   繁体   English

Docker 在 `docker run 上给出`no such file or directory`<image_id> `</image_id>

[英]Docker gives `no such file or directory` on `docker run <image_id>`

So I've just created my very first docker image (woohoo) and was able to run it on the original host system where it was created (Ubuntu 20.04 Desktop PC).所以我刚刚创建了我的第一个 docker 映像 (woohoo) 并且能够在创建它的原始主机系统上运行它 (Ubuntu 20.04 Desktop PC)。 The image was executed using docker run -it <image_id> .该图像是使用docker run -it <image_id>执行的。 The expected command (defined in CMD which is just a bash script) was run, and the expected output was seen.运行了预期的命令(在CMD中定义,它只是一个 bash 脚本),并且看到了预期的 output。 I assumed this meant I successfully created my very first docker image and so I pushed this to Docker Hub.我认为这意味着我成功创建了我的第一个 docker 映像,因此我将其推送到 Docker 集线器。

Docker Hub Docker 集线器

GitHub repo with original docker-compose.yml and Dockerfile GitHub 回购与原始docker-compose.ymlDockerfile

Here's the Dockerfile:这是 Dockerfile:

FROM ubuntu:20.04

# Required for Debian interaction
# (https://stackoverflow.com/questions/62299928/r-installation-in-docker-gets-stuck-in-geographic-area)
ENV DEBIAN_FRONTEND noninteractive

WORKDIR /home/benchmarking-programming-languages

# Install pre-requisites
#   Versions at time of writing:
#       gcc -- version (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
#       make -- GNU Make 4.2.1
#       curl -- 7.68.0
RUN apt update && apt install make build-essential curl wget tar -y

# Install `column`
RUN wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.35/util-linux-2.35-rc1.tar.gz
RUN tar xfz util-linux-2.35-rc1.tar.gz
WORKDIR /home/benchmarking-programming-languages/util-linux-2.35-rc1
RUN ./configure
RUN make column
RUN cp .libs/column /bin/
WORKDIR /home/benchmarking-programming-languages
RUN rm -rf util-linux-2.35-rc1*

RUN apt install python3 pip -y
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN apt install default-jdk-headless -y
RUN apt install rustc -y

# Install GoLang
RUN wget https://go.dev/dl/go1.17.8.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.8.linux-amd64.tar.gz
ENV PATH="/usr/local/go/bin:${PATH}"

# Install Haxe and Haxelib
RUN wget https://github.com/HaxeFoundation/haxe/releases/download/4.2.5/haxe-4.2.5-linux64.tar.gz
RUN tar xfz haxe-4.2.5-linux64.tar.gz
RUN ln -s /home/benchmarking-programming-languages/haxe_20220306074705_e5eec31/haxe /usr/bin/haxe
RUN ln -s /home/benchmarking-programming-languages/haxe_20220306074705_e5eec31/haxelib /usr/bin/haxelib
# # Install Neko (Haxe VM)
# RUN add-apt-repository ppa:haxe/snapshots -y
# RUN apt update
# RUN apt install neko -y

RUN if ! test -d /home/benchmarking-programming-languages; then mkdir /home/benchmarking-programming-languages && echo "Created directory /home/benchmarking-programming-languages."; fi
COPY . /home/benchmarking-programming-languages

RUN pip install -r /home/benchmarking-programming-languages/requirements_dev.txt

CMD [ "/home/benchmarking-programming-languages/benchmark.sh -v" ]

However, upon pulling the same image on my Windows 10 machine (same machine as above just dual booted) and a Windows 11 laptop using both the Docker Desktop application and the command line ( docker pull mariosyian/benchmarking-programming-languages followed by docker run -it <image_id> ). However, upon pulling the same image on my Windows 10 machine (same machine as above just dual booted) and a Windows 11 laptop using both the Docker Desktop application and the command line ( docker pull mariosyian/benchmarking-programming-languages followed by docker run -it <image_id> )。 Both which give me the following error两者都给我以下错误

Error invoking remote method 'docker-run-container': Error: (HTTP code 400) unexpected - failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/home/benchmarking-programming-languages/benchmark.sh -v": stat /home/benchmarking-programming-languages/benchmark.sh -v: no such file or directory: unknown

Despite this, running the image as a container with a shell ( docker run -it <image_id> sh ), I am successfully able to, not only see the file, but execute it with no errors, Can someone suggest a reason for why the error happens in the first place?尽管如此,将图像作为具有 shell 的容器运行( docker run -it <image_id> sh ),我成功地能够,不仅看到文件,而且执行它没有错误,有人可以提出原因错误首先发生? and how to fix it?以及如何解决?

In your Dockerfile you have specified the CMD as您的Dockerfile ,您已将CMD指定

CMD [ "/home/benchmarking-programming-languages/benchmark.sh -v" ]

This uses the JSON syntax of the CMD instruction, ie is an array of strings where the first string is the executable and each following string is a parameter to that executable.这使用CMD指令的 JSON 语法,即是一个字符串数组,其中第一个字符串是可执行文件,随后的每个字符串都是该可执行文件的参数。

Since you only have a single string specified docker tries to invoke the executable /home/benchmarking-programming-languages/benchmark.sh -v - ie a file named " benchmark.sh -v ", containing a space in its name and ending with -v .由于您只有一个指定的字符串docker尝试调用可执行文件/home/benchmarking-programming-languages/benchmark.sh -v - 即一个名为“ benchmark.sh -v ”的文件,其名称中包含一个空格并以-v But what you actually intended to do was to invoke the benchmark.sh script with the -v parameter .但是您实际上打算做的是使用-v参数调用benchmark.sh脚本。

You can do this by correctly specifying the parameter(s) as separate strings:您可以通过将参数正确指定为单独的字符串来做到这一点:

CMD ["/home/benchmarking-programming-languages/benchmark.sh", "-v"]

or by using the shell syntax :或使用shell 语法

CMD /home/benchmarking-programming-languages/benchmark.sh -v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM