1. 程式人生 > 實用技巧 >Windows環境搞好的Dockerfile檔案 在Linux上報錯了

Windows環境搞好的Dockerfile檔案 在Linux上報錯了

錯誤1:
standard_init_linux.go:187: exec user process caused "no such file or directory"

[root@izbp1dcscvry6tnoiqx8stz manager]# docker run --name managerV1 newhub.zkh360.com/zkh360/otter-manager-uat:v0.1
standard_init_linux.go:187: exec user process caused "no such file or directory"
[root@izbp1dcscvry6tnoiqx8stz manager]#
[root@izbp1dcscvry6tnoiqx8stz manager]# docker logs managerV1
standard_init_linux.go:
187: exec user process caused "no such file or directory" [root@izbp1dcscvry6tnoiqx8stz manager]#

原因:映象的entrypoint設定的啟動指令碼格式是dos,在linux系統上用vi修改成unix格式即可 【windows下操作之傷】
把.sh檔案逐個執行以下操作:

1)用vi開啟檔案
2)執行 :set ff 然後回車,可以看到fileformat=dos

3)修改成unix
:set ff=unix 回車
4)執行:set ff,可以看到已經改為 fileformat=unix

https://www.wandouip.com/t5i111338/

錯誤2:

[root@izbp1dcscvry6tnoiqx8stz manager]# docker run 793059909/otter-manager-uat:v0.2 -it bash
DOCKER_DEPLOY_TYPE=VM
==> INIT /alidata/init/02init-sshd.sh
==> EXIT CODE: 0
==> INIT /alidata/init/fix-hosts.py
/alidata/bin/main.sh: /alidata/init/fix-hosts.py: /usr/bin/python^M: bad interpreter: No such file or directory
==> EXIT CODE: 126 ==> INIT DEFAULT Generating SSH1 RSA host key: [ OK ] Starting sshd: [ OK ] Starting crond: [ OK ] ==> INIT DONE ==> RUN -it bash /alidata/bin/main.sh: line 27: exec: -i: invalid option exec: usage: exec [-cl] [-a name] [command [arguments ...]] [redirection ...] [root@izbp1dcscvry6tnoiqx8stz manager]#

看了下main.sh的第27行是:

#!/bin/bash

[ -n "${DOCKER_DEPLOY_TYPE}" ] || DOCKER_DEPLOY_TYPE="VM"
echo "DOCKER_DEPLOY_TYPE=${DOCKER_DEPLOY_TYPE}"

# run init scripts
for e in $(ls /alidata/init/*) ; do
    [ -x "${e}" ] || continue
    echo "==> INIT $e"
    $e
    echo "==> EXIT CODE: $?"
done

echo "==> INIT DEFAULT"
service sshd start
service crond start

#echo "check hostname -i: `hostname -i`"
#hti_num=`hostname -i|awk '{print NF}'`
#if [ $hti_num -gt 1 ];then
#    echo "hostname -i result error:`hostname -i`"
#    exit 120
#fi

echo "==> INIT DONE"
echo "==> RUN ${*}"
exec "${@}"


先解決Py報錯的事,相關也是檔案格式的事。果然:

仔細檢查報錯內容,並不會發現任何語句錯誤或者路徑錯誤,注意^m,這是windows下的斷元字元。所以問題就是,在多個環境上進行編寫,可能會因為字元(win/unix換行符不一樣)、縮排(兩個編輯環境的縮排tab/space不一致)均易導致這種神不知鬼不覺的錯誤,很難找到。

解決方法見上面*.sh指令碼的解決辦法

https://blog.csdn.net/qq_31331027/article/details/84590300