python-3.x - Luigi Pipeline in Dockerfile; unknown instruction PYTHONPATH
问题描述
I have this Dockerfile:
FROM python:3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD [
'PYTHONPATH="."', 'luigi', '--module', 'pipe',
'CreateAndFillIndex',
'--index', 'test',
'--http-auth', 'username:password',
'--host', 'localhost',
'--port', '9200'
]
Executing docker build -t suggestpipe . && docker run -it suggestpipe
with this Dockerfile I get the error:
unknown instruction: "PYTHONPATH='.'",
and if I remove that instruction, I get unknown instruction: "LUIGI",
so what am I doing wrong?
In requirements.txt there is a luigi dependency. And 'PYTHONPATH='.' was needed for running locally outside of Docker on my Mac, so I moved that CMD instruction into the Dockerfile too, but I am not sure if I need it. How do I run my pipeline?
解决方案
The Dockerfile syntax isn't actually JSON, and you can't have a line break after the [
. Docker in effect rewrites this to
CMD ["/bin/sh", "-c", "["]
(which would actually be valid! You probably have a /bin/[
binary! But the container would exit immediately with status code 0.)
and then moves on to the next line
"PYTHONPATH='.'", "luigi", "--module", "pipe",
where it gets confused because this doesn't actually look like a Dockerfile directive.
Just removing that newline on its own only gets you partway there. If you run
CMD ["PYTHONPATH='.'", "luigi", ...]
Docker won't launch a shell to try to run this; instead, it will look for a binary named exactly PYTHONPATH='.'
in the usual directories, and when it doesn't find e.g. /usr/bin/PYTHONPATH='.'
it will complain.
You shouldn't need to set this environment variable at all (especially since the pip install
step will install packages into the image's isolated global Python installation), and I'd just delete it:
CMD ["luigi", ...]
If you do need to set it, you need to use an explicit ENV directive
ENV PYTHONPATH .
推荐阅读
- amazon-web-services - 从 EMR 覆盖到 S3 存储桶需要很长时间
- excel - 定义一组不相邻的单元格
- python - 在第一个完成后无法运行辅助循环
- javascript - 为什么 Vue Router 直到我点击链接并重新加载所有网页后才加载
- html5-video - Video.js VOD 作为直播流
- android - 房间迁移失败 IllegalStateException
- installation - 在 Windows 上安装 Agda
- c# - 如何为这种类型的线球正确创建顶点?
- reactjs - 在 Visual Studio Code 中使用 useCallback() 获取 Typescript 错误
- git - 是否可以为每个 git 服务器指定不同的名称和电子邮件(使用子配置)?