在 $PATH Dockerfile 中找不到可执行文件
executable file not found in $PATH Dockerfile
我正在为应用程序构建 Docker 文件。我想在容器启动到运行时执行一个带参数的bash脚本,所以我把它作为一个入口点。但是,Docker找不到我的脚本所在的目录。 Thi 脚本位于 Intellij Idea 项目文件夹中,路径实际上如下所示:/home/user/Documents/folder1/folder2/folder3/Projectname/runapp.sh
我试图将此目录挂载为卷,但是在 运行 构建映像时发生错误:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"runapp.sh\": executable file not found in $PATH": unknown.
出现这种行为的原因可能是什么?我还能如何从 Docker 文件访问此 bash 脚本?
Docker文件如下所示:
FROM java:8
ENV SCALA_VERSION 2.11.8
ENV SBT_VERSION 1.1.1
ENV SPARK_VERSION 2.2.0
ENV SPARK_DIST spark-$SPARK_VERSION-bin-hadoop2.6
ENV SPARK_ARCH $SPARK_DIST.tgz
ENV NEO4J_CONFIG default
ENV BENCHMARK_NAME default
WORKDIR /opt
# Install Scala
RUN \
cd /root && \
curl -o scala-$SCALA_VERSION.tgz http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz && \
tar -xf scala-$SCALA_VERSION.tgz && \
rm scala-$SCALA_VERSION.tgz && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
# Install SBT
RUN \
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb
# Install Spark
RUN \
cd /opt && \
curl -o $SPARK_ARCH http://d3kbcqa49mib13.cloudfront.net/$SPARK_ARCH && \
tar xvfz $SPARK_ARCH && \
rm $SPARK_ARCH && \
echo 'export PATH=$SPARK_DIST/bin:$PATH' >> /root/.bashrc
EXPOSE 9851 9852 4040 7474 7687 7473
VOLUME /home/user/Documents/folder1/folder2/folder3/Projectname /workdir1
WORKDIR /workdir1
ENTRYPOINT ["runapp.sh"]
CMD ["$NEO4J_CONFIG", "$BENCHMARK_NAME"]
我认为您误解了 Docker 中的卷。 (参见 )
我在引用 :
A volume is a persistent data stored in /var/lib/docker/volumes/...
You can either declare it in a Dockerfile, which means each time a container is stated from the image, the volume is created (empty), even if you don't have any -v option.
You can declare it on runtime docker run -v [host-dir:]container-dir
.
combining the two (VOLUME + docker run -v) means that you can mount the content of a host folder into your volume persisted by the container in /var/lib/docker/volumes/...
.
docker volume create
creates a volume without having to define a Dockerfile and build an image and run a container. It is used to quickly allow other containers to mount said volume.
所以你应该在启动容器时使用docker run -v /home/user/Documents/folder1/folder2/folder3/Projectname:/workdir1
你的Docker文件卷声明应该是:
VOLUME /workdir1
也就是说,您同时定义了 Entrypoint 和 CMD。 CMD 是做什么用的?如果不使用 runapp.sh
,您将永远不会使用您的图像?我更喜欢只使用 CMD 进行开发,因为您仍然可以使用此语法进行 docker run -it my_container bash
调试。
这次我使用来自What is the difference between CMD and ENTRYPOINT in a Dockerfile?
的@Daishi 回答
The ENTRYPOINT specifies a command that will always be executed when the container starts.
The CMD specifies arguments that will be fed to the ENTRYPOINT.
If you want to make an image dedicated to a specific command you will use ENTRYPOINT ["/path/dedicated_command"]
Otherwise, if you want to make an image for general purpose, you can leave ENTRYPOINT
unspecified and use CMD ["/path/dedicated_command"]
as you will be able to override the setting by supplying arguments to docker run
此外,runapp.sh
不在您的 $PATH
中,并且您在没有绝对路径的情况下调用它,因此即使正确安装了卷,它也找不到该文件。
你可以只使用:
CMD /workdir1/runapp.sh "$NEO4J_CONFIG" "$BENCHMARK_NAME"
现在请注意,在您的主机上您提到 shell 脚本名为 script.sh
并且您在 Docker 文件中调用了 runapp.sh
,我希望它是打字错误。顺便说一句,您的脚本需要可执行。
我正在为应用程序构建 Docker 文件。我想在容器启动到运行时执行一个带参数的bash脚本,所以我把它作为一个入口点。但是,Docker找不到我的脚本所在的目录。 Thi 脚本位于 Intellij Idea 项目文件夹中,路径实际上如下所示:/home/user/Documents/folder1/folder2/folder3/Projectname/runapp.sh
我试图将此目录挂载为卷,但是在 运行 构建映像时发生错误:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"runapp.sh\": executable file not found in $PATH": unknown.
出现这种行为的原因可能是什么?我还能如何从 Docker 文件访问此 bash 脚本?
Docker文件如下所示:
FROM java:8
ENV SCALA_VERSION 2.11.8
ENV SBT_VERSION 1.1.1
ENV SPARK_VERSION 2.2.0
ENV SPARK_DIST spark-$SPARK_VERSION-bin-hadoop2.6
ENV SPARK_ARCH $SPARK_DIST.tgz
ENV NEO4J_CONFIG default
ENV BENCHMARK_NAME default
WORKDIR /opt
# Install Scala
RUN \
cd /root && \
curl -o scala-$SCALA_VERSION.tgz http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz && \
tar -xf scala-$SCALA_VERSION.tgz && \
rm scala-$SCALA_VERSION.tgz && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
# Install SBT
RUN \
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb
# Install Spark
RUN \
cd /opt && \
curl -o $SPARK_ARCH http://d3kbcqa49mib13.cloudfront.net/$SPARK_ARCH && \
tar xvfz $SPARK_ARCH && \
rm $SPARK_ARCH && \
echo 'export PATH=$SPARK_DIST/bin:$PATH' >> /root/.bashrc
EXPOSE 9851 9852 4040 7474 7687 7473
VOLUME /home/user/Documents/folder1/folder2/folder3/Projectname /workdir1
WORKDIR /workdir1
ENTRYPOINT ["runapp.sh"]
CMD ["$NEO4J_CONFIG", "$BENCHMARK_NAME"]
我认为您误解了 Docker 中的卷。 (参见
我在引用
A volume is a persistent data stored in
/var/lib/docker/volumes/...
You can either declare it in a Dockerfile, which means each time a container is stated from the image, the volume is created (empty), even if you don't have any -v option.
You can declare it on runtime
docker run -v [host-dir:]container-dir
. combining the two (VOLUME + docker run -v) means that you can mount the content of a host folder into your volume persisted by the container in/var/lib/docker/volumes/...
.
docker volume create
creates a volume without having to define a Dockerfile and build an image and run a container. It is used to quickly allow other containers to mount said volume.
所以你应该在启动容器时使用docker run -v /home/user/Documents/folder1/folder2/folder3/Projectname:/workdir1
你的Docker文件卷声明应该是:
VOLUME /workdir1
也就是说,您同时定义了 Entrypoint 和 CMD。 CMD 是做什么用的?如果不使用 runapp.sh
,您将永远不会使用您的图像?我更喜欢只使用 CMD 进行开发,因为您仍然可以使用此语法进行 docker run -it my_container bash
调试。
这次我使用来自What is the difference between CMD and ENTRYPOINT in a Dockerfile?
的@Daishi 回答The ENTRYPOINT specifies a command that will always be executed when the container starts.
The CMD specifies arguments that will be fed to the ENTRYPOINT.
If you want to make an image dedicated to a specific command you will use
ENTRYPOINT ["/path/dedicated_command"]
Otherwise, if you want to make an image for general purpose, you can leave
ENTRYPOINT
unspecified and useCMD ["/path/dedicated_command"]
as you will be able to override the setting by supplying arguments todocker run
此外,runapp.sh
不在您的 $PATH
中,并且您在没有绝对路径的情况下调用它,因此即使正确安装了卷,它也找不到该文件。
你可以只使用:
CMD /workdir1/runapp.sh "$NEO4J_CONFIG" "$BENCHMARK_NAME"
现在请注意,在您的主机上您提到 shell 脚本名为 script.sh
并且您在 Docker 文件中调用了 runapp.sh
,我希望它是打字错误。顺便说一句,您的脚本需要可执行。