英文:
Error while running Docker run docker: Error response from daemon
问题
以下是将在 Docker 容器内运行 Bash 脚本并接受两个输入并在容器内生成文件的 Docker 文件:
```Dockerfile
FROM ubuntu:latest
WORKDIR /app
COPY gencsv.sh /app/gencsv.sh
RUN chmod +x /app/gencsv.sh
CMD ["/bin/bash", "/app/gencsv.sh"]
docker run -dp 9393:9393 -v "$(pwd)/inputFile:/app/inputFile" input 2 8
docker: 容器创建失败的错误响应:OCI runtime create failed: container_linux.go:380: 启动容器进程引发了错误:exec: "2": 在 $PATH 中找不到可执行文件:未知。
<details>
<summary>英文:</summary>
Below is the Docker file which will run bash script inside docker container and takes two input and generates file inside container
FROM ubuntu:latest
WORKDIR /app
COPY gencsv.sh /app/gencsv.sh
RUN chmod +x /app/gencsv.sh
CMD ["/bin/bash", "/app/gencsv.sh"]`
docker run -dp 9393:9393 -v "$(pwd)/inputFile:/app/inputFile" input 2 8
> docker: Error response from daemon: OCI runtime create failed:
> container_linux.go:380: starting container process caused: exec: "2":
> executable file not found in $PATH: unknown.
</details>
# 答案1
**得分**: 1
`exec: "2": executable file not found in $PATH: unknown.` 这个错误意味着你尝试执行"2"作为命令,但(当然)它不是有效的命令,也不在$PATH中。
按照@Tuning85的建议使用Entrypoint。
CMD - 你可以覆盖默认命令。Docker认为你正在尝试执行`2 8`
Entrypoint - 无法被覆盖,命令行参数将作为参数传递给"app/gencsv.sh"脚本。
<details>
<summary>英文:</summary>
`exec: "2": executable file not found in $PATH: unknown.` This error means you're trying to execute "2" as a command, but (of course) it's not valid and not in $PATH.
Use Entrypoint as @Tuning85 said.
CMD - you can override the default command. Which docker thinks you are trying to do with `2 8`
Entrypoint - can't be overridden and the the command line parameters are passed as arguments to "app/gencsv.sh" script
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论