我有一个Docker文件,它与以下内容构建完美:docker build -t myfile .
但当我尝试使用 docker-compose 运行它时 - 它给了我一个错误:
web_1 | /bin/sh: 1: [/home/root/myproject/uwsgi.sh: not found
myproject_web_1 exited with code 127
Gracefully stopping... (press Ctrl+C again to force)
如果我手动启动此脚本 - 它可以正常工作。
Dockerfile 如下所示:
FROM ubuntu:14.04
ADD ./myproject/ /home/root/myproject/
WORKDIR /home/root/myproject/
# Some other stuff...
CMD ['/home/root/myproject/uwsgi.sh', 'start' ]
搬运工-compose.yml:
web:
build: .
ports:
- "8888:8888"
links:
- db
db:
image: mysql
为什么我收到此错误? 谢谢。
答案 0 :(得分:10)
我简化了你的例子
请参阅https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33229581
并使用:
<强>搬运工-compose.yml 强>
web:
build: .
ports:
- "8888:8888"
查找。
.
./docker-compose.yml
./Dockerfile
./myproject
docker build&amp;运行强>
docker-compose build
docker-compose run web
当然我得到
/bin/sh: 1: [/home/root/myproject/uwsgi.sh,: not found
假设这是因为myproject目录中没有uwsgi.sh。
如果我用
添加uwsgi.shecho 'echo $0 is there and called with params $@!' > myproject/uwsgi.sh
chmod +x myproject/uwsgi.sh
并使用
进行测试docker-compose run web /bin/bash
ls
cat uwsgi.sh
./uwsgi.sh start
它在那里,表现得像预期的那样:
root@9f06f8ff8c3b:/home/root/myproject# ls
uwsgi.sh
root@9f06f8ff8c3b:/home/root/myproject# cat uwsgi.sh
echo $0 is there and called with params $@!
root@9f06f8ff8c3b:/home/root/myproject# ./uwsgi.sh start
./uwsgi.sh is there and called with params start!
root@9f06f8ff8c3b:/home/root/myproject#
但是对于docker-compose运行web我仍然得到
/bin/sh: 1: [/home/root/myproject/uwsgi.sh,: not found
如果我向Dockerfile CMD行添加一个空白:
CMD [ '/home/root/myproject/uwsgi.sh', 'start' ]
结果是: / bin / sh:1:[:/ home / root /myproject / uwsgi.sh,:意外的运算符
让我们更接近。作为下一步,我将省略“开始”参数。
CMD [ '/home/root/myproject/uwsgi.sh' ]
这现在导致根本没有输出......
如果我将CMD线更改为:
CMD [ "/home/root/myproject/uwsgi.sh", "start" ]
我得到了
Cannot start container
0b9da138c43ef308ad70da4a7718cb96fbfdf6cda113e2ae0ce5e24de06f07cd: [8]
System error: exec format error
现在你可以继续像爱迪生一样:
我没有失败过。我刚刚找到了10,000种不起作用的方法。 直到找到
CMD [ "/bin/bash", "/home/root/myproject/uwsgi.sh", "start" ]
让你更接近结果:
/home/root/myproject/uwsgi.sh is there and called with params start!
CMD期望可执行文件作为第一个参数,例如
https://docs.docker.com/compose/
具有
CMD python app.py
作为一个例子。要运行shell脚本,您需要一个像bash这样的shell。 另请参阅https://stackoverflow.com/a/33219131/1497139
答案 1 :(得分:1)
对于其他寻求此错误消息的人:我发现我的情况是由于CMD行中缺少逗号引起的。错误状态:
$ grep ^CMD Dockerfile
CMD ["/bin/sh" "-c" "hostname"]
$ docker run --rm -it hostname
/bin/sh: 1: [/bin/sh: not found
正确插入逗号,这样可以解决问题:
$ grep ^CMD Dockerfile
CMD ["/bin/sh", "-c", "hostname"]