Easy way to ship Python/Flask apps using Docker

in #utopian-io7 years ago

I have been using NodeJs for a while for developing web applications. While it's not the perfect environment to develop, shipping applications is pretty easy as almost all hosting providers support it.

Recently I developed a Flask web app. It's very fun to program in Python. It's actually my favorite programming language. However, deploying Flask app turned out to be hard. I was trying to deploy on Microsoft Azure, which is quite popular cloud provider. The thing is languages like NodeJs, PHP etc. are well supported.

In order to solve my deployment issue, I turned to Docker. After reading bit of documentation, it actually turned out to be very easy process. I have to say I really enjoy building containers and pushing to remote servers. If it works on local, it works on remote servers 😄

Here is my Dockerfile

FROM python:3.6
MAINTAINER Nar Kumar Chhantyal
RUN apt update && apt install python-dev -y
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 8000
ENTRYPOINT ["gunicorn", "-b", "0.0.0.0:8000"]
CMD ["app:app"]

With that, I can now build container:

docker build . -t container-name:latest

And then run it:

docker run -p 8000:8000 container-name:latest

That's all.

I can run this in any machines which supports Docker. I can also share this Dockerfile with my coworkers and they will be able to setup this app with single command.

There is bit more to it, including uploading to remote registries like Docker Hub. I have pushed all the codebase on Github https://github.com/chhantyal/flask-docker.

Feel free to try it out and ship apps without getting stuck 🚀

Sort:  

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Nar from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Coin Marketplace

STEEM 0.20
TRX 0.20
JST 0.034
BTC 89955.66
ETH 3105.10
USDT 1.00
SBD 2.98