Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ENTRYPOINT with a python command raises command not found #101

Closed
igaloly opened this issue Dec 16, 2021 · 6 comments
Closed

Use ENTRYPOINT with a python command raises command not found #101

igaloly opened this issue Dec 16, 2021 · 6 comments

Comments

@igaloly
Copy link

igaloly commented Dec 16, 2021

When I use a python command in an ENTRYPOINT layer at the end on my Dockerfile, I get bash: line 1: python: command not found

I would love to hear your insight if I've mistaken somewhere (or if the issue isn't related to Mamba) :)

This is my Dockerfile.

FROM mambaorg/micromamba:0.19.1

WORKDIR /app

ENV LISTEN_PORT 80

COPY --chown=micromamba:micromamba base-env.yaml base-env.yaml
RUN micromamba install -y -f base-env.yaml && \
    micromamba clean --all --yes
# (otherwise python will not be found)
ARG MAMBA_DOCKERFILE_ACTIVATE=1
COPY . .
WORKDIR ./src
ENTRYPOINT python -m service.start
@wholtz
Copy link
Member

wholtz commented Dec 16, 2021

hi @igaloly -- thank you for your interest in micromamba.

Running a program from a conda environment in the ENTRYPOINT seems like it would be a common use case but somehow it hasn't made it into our test suite yet. The best solution right now would be to replace your last line with:

ENTRYPOINT ["/usr/local/bin/_entrypoint.sh", "python", "-m", "service.start"]

It is critical that you use the 'exec' form of ENTRYPOINT as I have shown.

I'm going to investigate if there is a more automatic way the conda environment can be activated for the ENTRYPOINT command, but from the reading I've done so far, I'm not optimistic.

We do need to add some tests and documentation around this usage pattern.

@wholtz
Copy link
Member

wholtz commented Dec 16, 2021

I should also mention that you do not need:

ARG MAMBA_DOCKERFILE_ACTIVATE=1

As the ENTRYPOINT commands do not run during the execution of docker build ....

@igaloly
Copy link
Author

igaloly commented Dec 17, 2021

Hi @wholtz, thanks for the quick and professional response!
Your suggestion works :)

I would love to hear from you about the underlying mechanism that prevented from ENTRYPOINT python -m service.start to work and let ENTRYPOINT ["/usr/local/bin/_entrypoint.sh", "python", "-m", "service.start"] work.

Moreover, I would love to understand how ARG MAMBA_DOCKERFILE_ACTIVATE=1 lets the ability to RUN python commands at build-time.

@maresb
Copy link
Collaborator

maresb commented Dec 17, 2021

@igaloly, going back to your original example, I would recommend simply replacing ENTRYPOINT by CMD. The CMD statement defines the default command to run from docker run containername [command] when no command is specified. I think that's directly in-line with what you expected.

The ENTRYPOINT command defines the default shell for the docker run command. By setting it to _entrypoint.sh, we provide an activated Bash shell.

The mechanism for ARG MAMBA_DOCKERFILE_ACTIVATE=1 is accomplished via the SHELL _shell.sh command. Similar to ENTRYPOINT, the SHELL command defines the default shell for the docker build command.

Does this clear up all your questions?

@wholtz and I have been working on the README lately. We'd greatly appreciate any advice for how to make them more understandable!

@igaloly
Copy link
Author

igaloly commented Dec 17, 2021

@maresb Definitely clears up my questions. You answered greatly. Thank you very much! :)

@igaloly igaloly closed this as completed Dec 17, 2021
@wholtz
Copy link
Member

wholtz commented Dec 17, 2021

@igaloly, going back to your original example, I would recommend simply replacing ENTRYPOINT by CMD. The CMD statement defines the default command to run from docker run containername [command] when no command is specified. I think that's directly in-line with what you expected.

Using the CMD would preclude you from passing additional arguments for service.start on the command line. So if you need that functionality, then you'd have to stick with the ENTRYPOINT I proposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants