使用Docker并找不到文件

时间:2019-10-01 15:44:13

标签: docker dockerfile docker-for-windows docker-desktop

我正在尝试使用Docker,并且正在遵循getting started文档,但是我的测试脚本显示“未找到”。

我正在尝试运行脚本:test.sh(仅包含echo "Hello"

我的docker目录包含 app/ docker-compose/ Dockerfile test.sh

Dockerfile包含:

FROM openjdk:8u181
WORKDIR /app
COPY . /app
EXPOSE 69
ENV NAME mer
CMD "test.sh"

我这样构建它:

$ docker build --tag=mer .
Sending build context to Docker daemon  303.8MB
Step 1/6 : FROM openjdk:8u181
 ---> 82942d9df443
Step 2/6 : WORKDIR /app
 ---> Using cache
 ---> b2586c6519ea
Step 3/6 : COPY . /app
 ---> 8ecd700feafe
Step 4/6 : EXPOSE 69
 ---> Running in 343cb5014528
Removing intermediate container 343cb5014528
 ---> 629cdc57f74e
Step 5/6 : ENV NAME mer
 ---> Running in 53844c2ea6fd
Removing intermediate container 53844c2ea6fd
 ---> b952a8f45dc8
Step 6/6 : CMD "test.sh"
 ---> Running in 1f1ef99503b8
Removing intermediate container 1f1ef99503b8
 ---> ffe838007e82
Successfully built ffe838007e82
Successfully tagged mer:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

并像这样运行它:

$ docker run mer:latest
/bin/sh: 1: test.sh: not found

为什么说“ test.sh:未找到”?

我的环境:带有Docker Desktop 2.1的Windows 10通过Cygwin运行命令

1 个答案:

答案 0 :(得分:1)

您需要从test.sh目录中引用/app并将其设置为COPY后引用WORKDIR

CMD "/app/test.sh"

我建议您考虑使用ENTRYPOINT而不是CMD

由于您正在使用Bash进程,因此您可能希望继续使用shell form,即

ENTRYPOINT "/app/test.sh"