sys.argv 在使用 Dockerfile + pipenv + baker 时迷路了
sys.argv got lost when using Dockerfile + pipenv + baker
考虑以下 app.py
#!/usr/bin/env python
import baker
@baker.command
def initial_setup(setting1, setting2):
# do some important prep work here
@baker.command
def start(arg1, arg2):
# do your thing
if __name__ == '__main__':
baker.run()
这里我使用 baker 将我的函数公开为子命令。
我还有一个docker文件:
FROM alpine
COPY . /app
WORKDIR /app
ENV SHELL=/bin/ash
RUN apk update && apk upgrade && apk add python3
RUN python3 -m pip install pip --upgrade
RUN python3 -m pip install pipenv
RUN pipenv install
RUN pipenv run ./app.py initial_setup foo bar
CMD pipenv run ./app.py start baz qux
当我 运行 docker build .
时 initial_setup 步骤失败
Step ...: RUN pipenv run ./app.py initial_setup foo bar
[...]
No command specified
The command '/bin/sh -c pipenv run ./app.py initial_setup foo bar' returned a non-zero code: 1
当我在我的命令行中 运行 pipenv run ./app.py initial_setup foo bar
时它工作,但在 Dockerfile 构建内部似乎 sys.argv
没有传递给面包师。
知道如何说服 docker 文件将参数传递到我的应用程序吗?
更新:
- 我尝试将 initial_setup 命令移动到 shell 脚本中,并在 ash 上使用 bash,但都无济于事。
- 添加了我的 Dockerfile 中省略的步骤以响应 @stacksonstacks 的评论。
结果sys.argv
如期通过,只能怪我太笨了:
我有一个拼写错误 initial_setup
,在这种情况下 baker 无法将参数识别为命令,因此出现错误消息 "No command specified" .
考虑以下 app.py
#!/usr/bin/env python
import baker
@baker.command
def initial_setup(setting1, setting2):
# do some important prep work here
@baker.command
def start(arg1, arg2):
# do your thing
if __name__ == '__main__':
baker.run()
这里我使用 baker 将我的函数公开为子命令。
我还有一个docker文件:
FROM alpine
COPY . /app
WORKDIR /app
ENV SHELL=/bin/ash
RUN apk update && apk upgrade && apk add python3
RUN python3 -m pip install pip --upgrade
RUN python3 -m pip install pipenv
RUN pipenv install
RUN pipenv run ./app.py initial_setup foo bar
CMD pipenv run ./app.py start baz qux
当我 运行 docker build .
时 initial_setup 步骤失败
Step ...: RUN pipenv run ./app.py initial_setup foo bar
[...]
No command specified
The command '/bin/sh -c pipenv run ./app.py initial_setup foo bar' returned a non-zero code: 1
当我在我的命令行中 运行 pipenv run ./app.py initial_setup foo bar
时它工作,但在 Dockerfile 构建内部似乎 sys.argv
没有传递给面包师。
知道如何说服 docker 文件将参数传递到我的应用程序吗?
更新:
- 我尝试将 initial_setup 命令移动到 shell 脚本中,并在 ash 上使用 bash,但都无济于事。
- 添加了我的 Dockerfile 中省略的步骤以响应 @stacksonstacks 的评论。
结果sys.argv
如期通过,只能怪我太笨了:
我有一个拼写错误 initial_setup
,在这种情况下 baker 无法将参数识别为命令,因此出现错误消息 "No command specified" .