Python standard_init_linux.go:211: exec 用户进程导致“exec 格式错误”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/58298774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
standard_init_linux.go:211: exec user process caused "exec format error"
提问by Pandit Biradar
I am building the Dockerfile for python script which will run in minikube windows 10 system below is my Dockerfile
我正在为 python 脚本构建 Dockerfile,它将在 minikube windows 10 系统中运行,下面是我的 Dockerfile
Building the docker using the below command
docker build -t python-helloworld .
使用以下命令构建 docker
docker build -t python-helloworld .
and loading that in minikube docker demon
docker save python-helloworld | (eval $(minikube docker-env) && docker load)
并将其加载到 minikube docker Demon 中
docker save python-helloworld | (eval $(minikube docker-env) && docker load)
Docker File
Docker 文件
FROM python:3.7-alpine
#add user group and ass user to that group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
#creates work dir
WORKDIR /app
#copy python script to the container folder app
COPY helloworld.py /app/helloworld.py
#user is appuser
USER appuser
ENTRYPOINT ["python", "/app/helloworld.py"]
pythoncronjob.yml file (cron job file)
pythoncronjob.yml 文件(cron 作业文件)
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: python-helloworld
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
backoffLimit: 5
template:
spec:
containers:
- name: python-helloworld
image: python-helloworld
imagePullPolicy: IfNotPresent
command: [/app/helloworld.py]
restartPolicy: OnFailure
Below is the command to run this Kubernetes job
kubectl create -f pythoncronjob.yml
以下是运行此 Kubernetes 作业的命令
kubectl create -f pythoncronjob.yml
But getting the below error job is not running scuessfully but when u ran the Dockerfile alone its work fine
但是获得以下错误作业并没有成功运行,但是当您单独运行 Dockerfile 时,它的工作正常
standard_init_linux.go:211: exec user process caused "exec format error"
standard_init_linux.go:211: exec 用户进程导致“exec 格式错误”
采纳答案by LinPy
I can see that you add the command command: [/app/helloworld.py]
to yaml file.
我可以看到您将命令添加command: [/app/helloworld.py]
到 yaml 文件中。
so you need to (in Dockerfile):
所以你需要(在 Dockerfile 中):
RUN chmod +x /app/helloworld.py
set shebang to your py
file:
将shebang设置为您的py
文件:
#!/usr/bin/env python # whatever your defualt python to run the script
or setup the command the same as you did in Dockerfile
或设置与您相同的命令 Dockerfile
回答by Sajith Kumar Ganesan
I recently encountered the problem when running a logstash container
最近在运行logstash容器时遇到了这个问题
standard_init_linux.go:211: exec user process caused "exec format error"
standard_init_linux.go:211: exec 用户进程导致“exec 格式错误”
Noticed that the shebang line (#!/bin/sh) on the entrypoint.sh was typed in the second line instead of the first line of the entrypoint.sh file.
请注意,entrypoint.sh 上的 shebang 行 (#!/bin/sh) 是在 entrypoint.sh 文件的第二行而不是第一行中键入的。
When the shebang line is made as to the first line in the script, the error went away and "docker run -it logstashimage:latest sh"worked perfectly.
当将shebang行作为脚本中的第一行时,错误消失了,“docker run -it logstashimage:latest sh”完美地工作。
回答by DennisKot
Another two reasons could raise this issue if you run docker on Windows:
如果您在Windows上运行 docker,另外两个原因可能会引发此问题:
- scripts line endings are not LF (linux)
- scripts encoding should be utf-8 + BOM
- 脚本行结尾不是 LF (linux)
- 脚本编码应为 utf-8 + BOM