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

Windows环境搞好的Dockerfile文件 在Linux上报错了

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行是:
Windows环境搞好的Dockerfile文件 在Linux上报错了

 

 

#!/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







Windows环境搞好的Dockerfile文件 在Linux上报错了

上一篇:C# winform 开发采血中心业务自动打印贴管系统


下一篇:windows 下部署 .netcore 到 windows service