Easy way to ship Python/Flask apps using Docker

3년 전

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 🚀

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
STEEMKR.COM IS SPONSORED BY
ADVERTISEMENT
Sort Order:  trending

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.