最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

docker - Use one CMD for DEV and another CMD for PROD in the same Dockerfile - Stack Overflow

programmeradmin1浏览0评论

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"]

?

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"]

?

Share Improve this question asked Feb 5 at 13:37 anjaneshanjanesh 4,2519 gold badges52 silver badges72 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论