TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to Write Dockerfiles for Python Web Apps

44 pointsby praveenwebabout 7 years ago

6 comments

c0l0about 7 years ago
<p><pre><code> Using an appropriate base image (debian for dev, alpine for production). </code></pre> No you don&#x27;t. It&#x27;s nonsensical to use a &quot;convenient&quot; development environment, and then make the production application work in something more bare-bones&#x2F;stripped down&#x2F;different. I&#x27;ve never used Alpine Linux, but even I know there&#x27;s a LOT of subtle differences between it and Debian. Nontrivial stuff that matters, like C library implementation (GNU libc vs. musl) and init system (systemd vs. sysv init). You don&#x27;t want that, because it opens up a multiverse full of potential, exclusively bad surprises that you&#x27;ll be unprepared to debug.
评论 #16472130 未加载
评论 #16473379 未加载
评论 #16475254 未加载
shocksabout 7 years ago
&gt; Using an appropriate base image (debian for dev, alpine for production).<p>Seems to me like this is a good way to introduce subtle differences between dev and prod.<p>I&#x27;d just use the same base images for everything. Consistency is king.
评论 #16472162 未加载
评论 #16472176 未加载
评论 #16472136 未加载
rcarmoabout 7 years ago
One thing that’s missing from the RUN command is ‘-u’, for unbuffered output (essential when using the default loggers).<p>But there are simpler ways to build dev images using build stages... I maintain two for my own use, one for web dev and another for ML&#x2F;back-end stuff:<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;rcarmo&#x2F;alpine-python" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rcarmo&#x2F;alpine-python</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;rcarmo&#x2F;ubuntu-python" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rcarmo&#x2F;ubuntu-python</a> (because musl doesn’t play well with some binary dependencies)<p>I also tend to rely on uwsgi or sanic rather than gunicorn (which feels a bit dated to me) but those boil down to personal preference.
评论 #16472155 未加载
deepsunabout 7 years ago
Just curious, why do you need gunicorn for auto-restarting the server inside a docker container, if you can just restart the container? It&#x27;s pretty lightweight operation for config changes, imo.
评论 #16472133 未加载
评论 #16472135 未加载
hartrorabout 7 years ago
<p><pre><code> COPY src&#x2F;requirements.txt .&#x2F; RUN pip install -r requirements.txt </code></pre> This has always confounded me as we always put `-e .` in our requirements.txt. Has this fallen out of favour? It doesn&#x27;t appear the author&#x27;s application needs to be installed like most pyramid or click applications do.
评论 #16483778 未加载
essetiabout 7 years ago
out of curisoity, why gunicorn instead of uwsgi?
评论 #16472043 未加载
评论 #16471903 未加载