项目内容:
rob@work:~/git/proj $ ls
lib node_modules props.json start.sh
app.js Dockerfile package.json README.md
start.sh
..
rob@work:~/git/proj $ cat start.sh
#/bin/bash
# do things
/some/other/stuff
echo "Starting app .."
node app.js
Dockerfile
..
FROM somewhere.com/dependencyProj
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
COPY props.json /etc/someService.d/props.json
EXPOSE 4101
ENTRYPOINT ["/start.sh"]
构建泊坞窗图片:
rob@work:~/git/proj $ docker build -t dx/proj:0.0.1 .
Sending build context to Docker daemon 59.99 MB
Step 1 : FROM somewhere.com/dependencyProj
latest: Pulling from dependencyProj
420890c9e918: Already exists
8ff1af46fe3d: Already exists
6db3a1c6f4ca: Already exists
d82a90c4ea1b: Already exists
f32685681727: Already exists
797dfb291196: Already exists
3a713b0b523e: Already exists
a9c617bff63b: Already exists
9ab84732ac6e: Already exists
2a85e0afdd4d: Already exists
a56b24146ce4: Already exists
0a91b00da1f7: Already exists
836b0e7c1105: Already exists
Digest: sha256:36b7a32bd12b85cbb2fb3203d43807c9b8735d6ceb50d813b76bfe2e5c3ebeb4
Status: Downloaded newer image for somewhere.com/dependencyProj:latest
---> 7c52bbbc3feb
Step 2 : RUN mkdir -p /usr/src/app
---> Running in aab7cf1f7974
---> 250317f63adf
Removing intermediate container aab7cf1f7974
Step 3 : WORKDIR /usr/src/app
---> Running in f60088532610
---> 60f3d9fe88c4
Removing intermediate container f60088532610
Step 4 : COPY . /usr/src/app
---> 004e0a440fb5
Removing intermediate container f247d134d88b
Step 5 : COPY props.json /etc/someService.d/props.json
---> 03b48249c94c
Removing intermediate container a3636849765d
Step 6 : EXPOSE 4101
---> Running in 0056e5c20264
---> 867765176927
Removing intermediate container 0056e5c20264
Step 7 : ENTRYPOINT /start.sh
---> Running in 80ae316b0629
---> d1e65def77ce
Removing intermediate container 80ae316b0629
Successfully built d1e65def77ce
运行docker image:
rob@work:~/git/proj $ docker run -d dx/proj:0.0.1
0fd1f8087cc5be3e085454cf99b7a3795b9ce15909b0f416ae39380f93feaa44
docker: Error response from daemon: Container command '/start.sh' not found or does not exist..
答案 0 :(得分:31)
在Windows上,在构建docker镜像时,我也常常在构建图像后得到相同的错误,那个shell脚本丢失了......路径和shebang也是正确的。
稍后,我读了一些可能是由于编码问题导致的问题。我只是在崇高的编辑器中打开文件,然后是..VIEW-> Line Endings-> UNIX,只需保存文件,并重建图像。一切都很好。
当我从windows构建图像时,我收到了这个错误。
其他选项:
有时,我们忘记手动更改线路格式。因此,我们可以做的是在 dockerfile 中的EntryPoint之前添加此运行语句。它将以LF格式对文件进行编码。
RUN sed -i 's/\r$//' $app/filename.sh && \
chmod +x $app/filename.sh
ENTRYPOINT $app/filename.sh
答案 1 :(得分:13)
你有一些问题:
您必须使用./start.sh
从当前目录运行start.sh
文件。 /start.sh
在根start.sh
中运行/
,但不存在。
start.sh
脚本中的shebang行错误,必须是#!/bin/bash
。
您还必须通过运行start.sh
为chmod +x start.sh
设置可执行权限。