bash 为什么“docker run”会出现“没有这样的文件或目录”的错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31972673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:25:20  来源:igfitidea点击:

Why does "docker run" error with "no such file or directory"?

bashshelldockercontainersdockerfile

提问by Kingamere

I am trying to run a container which runs an automated build. Here is the dockerfile:

我正在尝试运行一个运行自动构建的容器。这是 dockerfile:

   FROM ubuntu:14.04
    MAINTAINER pmandayam

    # update dpkg repositories
    RUN apt-get update

    # install wget
    RUN apt-get install -y wget

    # get maven 3.2.2
    RUN wget --no-verbose -O /tmp/apache-maven-3.2.2.tar.gz http://archive.apache.or
    g/dist/maven/maven-3/3.2.2/binaries/apache-maven-3.2.2-bin.tar.gz

    # verify checksum
    RUN echo "87e5cc81bc4ab9b83986b3e77e6b3095 /tmp/apache-maven-3.2.2.tar.gz" | md5
    sum -c

    # install maven
    RUN tar xzf /tmp/apache-maven-3.2.2.tar.gz -C /opt/
    RUN ln -s /opt/apache-maven-3.2.2 /opt/maven
    RUN ln -s /opt/maven/bin/mvn /usr/local/bin
    RUN rm -f /tmp/apache-maven-3.2.2.tar.gz
    ENV MAVEN_HOME /opt/maven

    # remove download archive files
    RUN apt-get clean

    # set shell variables for java installation
    ENV java_version 1.8.0_11
    ENV filename jdk-8u11-linux-x64.tar.gz
    ENV downloadlink http://download.oracle.com/otn-pub/java/jdk/8u11-b12/$filename

    # download java, accepting the license agreement
    RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie
    " -O /tmp/$filename $downloadlink

    # unpack java
    RUN mkdir /opt/java-oracle && tar -zxf /tmp/$filename -C /opt/java-oracle/
    ENV JAVA_HOME /opt/java-oracle/jdk$java_version
    ENV PATH $JAVA_HOME/bin:$PATH

    # configure symbolic links for the java and javac executables
    RUN update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 20000 &
    & update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 20000

    # install mongodb
    RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
    ' | sudo tee /etc/apt/sources.list.d/mongodb.list && \
            apt-get update && \
                apt-get --allow-unauthenticated install -y mongodb-org mongodb-org-s
    erver mongodb-org-shell mongodb-org-mongos mongodb-org-tools && \

                    echo "mongodb-org hold" | dpkg --set-selections && \
                        echo "mongodb-org-server hold" | dpkg --set-selections && \
                            echo "mongodb-org-shell hold" | dpkg --set-selections &&
     \
                                echo "mongodb-org-mongos hold" | dpkg --set-selectio
    ns && \
                                    echo "mongodb-org-tools hold" | dpkg --set-selec
    tions

    RUN mkdir -p /data/db
    VOLUME /data/db

    EXPOSE 27017

    COPY build-script /build-script

    CMD ["/build-script"]

I can build the image successfully but when I try to run the container I get this error:

我可以成功构建映像,但是当我尝试运行容器时,出现此错误:

$ docker run mybuild
no such file or directory
Error response from daemon: Cannot start container 3e8aa828909afcd8fb82b5a5ac894
97a537bef2b930b71a5d20a1b98d6cc1dd6: [8] System error: no such file or directory

what does it mean 'no such file or directory'?

“没有这样的文件或目录”是什么意思?

Here is my simple script:

这是我的简单脚本:

#!/bin/bash

sudo service mongod start

mvn clean verify

sudo service mongod stop

I copy it like this: COPY build-script /build-script

我像这样复制它:COPY build-script /build-script

and run it like this: CMD ["/build-script"] not sure why its not working

并像这样运行它: CMD ["/build-script"] 不知道为什么它不起作用

回答by Adrian Mouat

Using serviceisn't going to fly - the Docker base images are minimal and don't support this. If you want to run multiple processes, you can use supervisor or runit etc.

使用service不会成功 - Docker 基础镜像很少,不支持这一点。如果要运行多个进程,可以使用 supervisor 或 runit 等。

In this case, it would be simplest just to start mongo manually in the script e.g. /usr/bin/mongod &or whatever the correct incantation is.

在这种情况下,最简单的方法是在脚本中手动启动 mongo,例如/usr/bin/mongod &或任何正确的咒语。

BTW the lines where you try to clean up don't have much effect:

顺便说一句,您尝试清理的行没有太大影响:

RUN rm -f /tmp/apache-maven-3.2.2.tar.gz
...
# remove download archive files
RUN apt-get clean

These files have already been committed to a previous image layer, so doing this doesn't save any disk-space. Instead you have to delete the files in the same Dockerfile instruction in which they're added.

这些文件已经提交到先前的图像层,因此这样做不会节省任何磁盘空间。相反,您必须在添加它们的同一 Dockerfile 指令中删除文件。

Also, I would consider changing the base image to a Java one, which would save a lot of work. However, you may have trouble finding one which bundles the official Oracle JDK rather than OpenJDK if that's a problem.

此外,我会考虑将基本映像更改为 Java 映像,这将节省大量工作。但是,如果有问题,您可能很难找到捆绑官方 Oracle JDK 而不是 OpenJDK 的工具。