-1

I have in my Dockerfile :

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "nerul.wsgi:application"]

But docker run -p 8000:8000 -v ${PWD}:/app nerul-docker doesn't work because it says "ModuleNotFoundError: No module named 'nerul'" even though my directory structure is correct

docker run -p 8000:8000 nerul-docker works but there's no hot-reload.

So how do I make my Dockerfile such that for dev it has

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

while for PROD it has

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "nerul.wsgi:application"]

?

1 Answer 1

0

You can provide an alternate command when you run the container. Anything you put after the docker run command replaces the Dockerfile CMD.

So, you can run for example,

docker run -p 8000:8000 \
  -v "$HOME/src/other-app:/app" \
  ./manage.py runserver 0.0.0.0:8000

As I hint in the specific -v line, this means you aren't using any of the code in the image, only the Python interpreter from the base image and any libraries you RUN pip install. If you RUN any other commands to set up the source tree, that work will be lost in this setup. Correspondingly, this setup may "work on your machine" but isn't really related to the image you're eventually deploying. You might find it simpler to use the Python interpreter that's already on your (MacOS or Linux) host system.

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

Comments

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.