我正在为 python 脚本构建 Dockerfile,它将在 minikube windows 10 系统中运行 下面是我的 Dockerfile
使用以下命令 docker build -t python-helloworld .
并将其加载到 minikube docker 恶魔 docker save python-helloworld | (eval $(minikube docker-env) && docker load)
码头工人文件
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 文件(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
下面是运行这个 Kubernetes 作业的命令 kubectl create -f pythoncronjob.yml
但是得到以下错误作业并没有成功运行,但是当你单独运行 Dockerfile 时,它的工作正常
standard_init_linux.go:211:exec 用户进程导致“exec 格式错误”
原文由 Pandit Biradar 发布,翻译遵循 CC BY-SA 4.0 许可协议
我可以看到您将命令
command: [/app/helloworld.py]
添加到 yaml 文件中。所以你需要(在 Dockerfile 中):
将 shebang 设置为您的
py
文件:或像在
Dockerfile
中一样设置命令