Search code examples
pythondockerdockerfilecommand-line-argumentspipenv

sys.argv got lost when using Dockerfile + pipenv + baker


Consider the following 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()

Here I am using baker that exposes my functions as sub-commands.

I also have a docker file:

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

When I am running docker build . the initial_setup step fails with

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

When I am running pipenv run ./app.py initial_setup foo bar in my command line it works, but inside the Dockerfile build it seems that the sys.argv is not passed to baker.

Any idea how to convince the docker file to pass the arguments along to my app?

Update:

  • I tried both moving the initial_setup command into a shell script, and using bash over ash, both to no avail.
  • Added a steps omitted from my Dockerfile in response to @stacksonstacks's comment.

Solution

  • It turned out that sys.argv was passed as expected and that I have only my stupidity to blame:

    I had a typo spelling initial_setup, and in such cases baker doesn't recognize the argument as a command, hence the error message "No command specified".