我簡化你的例子有點
看到https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33229581
和使用:
泊塢窗,compose.yml
web:
build: .
ports:
- "8888:8888"
發現。
.
./docker-compose.yml
./Dockerfile
./myproject
搬運工建立&運行
docker-compose build
docker-compose run web
,當然我得到
/bin/sh: 1: [/home/root/myproject/uwsgi.sh,: not found
假設這是因爲在MyProject目錄沒有uwsgi.sh。
如果我添加uwsgi.sh與
echo '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
它的存在對其進行測試和行爲與預期相同:
[email protected]:/home/root/myproject# ls
uwsgi.sh
[email protected]:/home/root/myproject# cat uwsgi.sh
echo $0 is there and called with params [email protected]!
[email protected]:/home/root/myproject# ./uwsgi.sh start
./uwsgi.sh is there and called with params start!
[email protected]:/home/root/myproject#
但碼頭工人,撰寫運行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
,現在你可以繼續像愛迪生一樣的方法:
我沒有失敗。我剛剛發現了萬種不起作用的方法。 ,直到你找到
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
您使用的是.dockerignore? https://github.com/docker/compose/issues/2109#issuecomment-144163891 – VonC
好,如果它說uwsgi.sh沒有找到我首先使用bash,看看它是否存在以及擁有什麼所有權和權限... –