【发布时间】:2021-11-20 21:17:49
【问题描述】:
我在解压缩已复制到 docker 映像上的文件时遇到问题。我尝试使用
RUN unzip /file.zip 和我遇到的其他技术,但似乎没有任何效果。
然后我尝试将解压缩操作添加到我用作 docker 映像入口点的 shell 脚本中。
这是构建的 yaml 文件:
RUN mkdir jobs
COPY test_0.1.zip /jobs/test_0.1.zip
COPY entrypoint.sh /jobs/
RUN cd jobs/
CMD [ "/jobs/entrypoint.sh" ]
这里是shell脚本的代码:
function setup()
{
echo "Preparing files for job execution"
unzip test_0.1.zip
}
setup &
b=$!
wait $b
cd test/
chmod +x test_run.sh
./test_run.sh
当我只使用图像运行容器时,我收到此错误:
unzip: can't open test_0.1.zip[.zip]
/jobs/entrypoint.sh: cd: line 10: can't cd to test/: No such file or directory
chmod: test_run.sh: No such file or directory
/jobs/entrypoint.sh: line 12: ./test_run.sh: not found
解压缩操作不起作用,但是当我在命令行中访问容器时,我可以运行脚本并且它可以工作。
我的 Dockerfile 或我的 shell 脚本有问题,还是 docker 特有的问题?
感谢您的回复,如果此类问题已被提出和回答,我们深表歉意。
【问题讨论】:
-
Dockerfile 中的倒数第二行没有任何作用。改用
WORKDIR指令,我想这就是你想要的。 -
@UlrichEckhardt 是的,这是问题所在,使用 WORKDIR 后它工作正常
标签: linux docker shell dockerfile sh