1

I have the following docker setup:

python27.Dockerfile

FROM python:2.7
COPY ./entrypoint.sh /entrypoint.sh
RUN mkdir /src
RUN apt-get update && apt-get install -y bash libmysqlclient-dev python-pip build-essential && pip install virtualenv
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000
WORKDIR /src
CMD source /src/env/bin/activate && python /src/manage.py runserver

entrypoint.sh

#!/bin/bash

# some code here...
# some code here...
# some code here...

exec "$@"

Whenever I try to run my docker container I get python27 | /bin/sh: 1: source: not found.

I understand that the error comes from the fact that the command is run with sh instead of bash, but I can't understand why is that happening, given the fact that I have the correct shebang at the top of my entrypoint.

Any ideas why is that happening and how can I fix it?

2
  • Your shebang has bash? Commented May 7, 2017 at 16:58
  • @johnharris85 Yes, I'm installing it in the 4th line in my Dockerfile. Commented May 7, 2017 at 17:00

1 Answer 1

2

The problem is that for CMD you're using the shell form that uses /bin/sh, and the /src/env/bin/activate likely contains a "source" command, which isn't available on POSIX /bin/sh (the equivalent builtin would be just .).

You must use the exec form for CMD using brackets:

CMD ["/bin/bash", "-c", "source /src/env/bin/activate && python /src/manage.py runserver"]

More details in:

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, that work. But I still can't understand why is this happening. I mean, the entrypoint get's executed with the command (as arguments) of the CMD. The entrypoint executes exec '$@', which is basically exec source ..... && python ...., and all that inside bash. So why is the source part failing?
See the last part of the last link of my response, on the result of the multiple different ENTRYPOINT / CMD combinations. In your case, it would be: /entrypoint.sh /bin/sh -c source ...
PD: By exec form they mean using the exec*() system calls and not the exec builtin shell command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.