Skip to content

Instantly share code, notes, and snippets.

@freeslugs
Last active November 17, 2015 17:18
Show Gist options
  • Save freeslugs/df97e1339933dcfa56f0 to your computer and use it in GitHub Desktop.
Save freeslugs/df97e1339933dcfa56f0 to your computer and use it in GitHub Desktop.
how to docker - flask

how to python - flask

install docker on mac

  • you'll need virtualbox: brew cask install virtualbox
  • brew install docker
  • install toolbox

run docker

pop up the docker quickstart terminal. it'll start up the VM and you'll be all set up.

  • it'll show text docker is configured to use the default machine with IP 192.168.99.100 ==> remember that IP address

set up app

create file app.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def main():
    return 'Hello World!'

if __name__ == '__main__':
    app.run('0.0.0.0')

and requirements.txt

flask==0.10.1

if you run python app.py locally you can visit localhost:5000 and you'll see "Hello world!".

dockerize the app

  • create a Dockerfile.
FROM python:2.7

RUN mkdir /code
WORKDIR /code

ADD requirements.txt /code/
RUN pip install -r requirements.txt

ADD . /code/
EXPOSE 5000

now we run the app in docker.

  • docker build -t flaskapp .
  • docker run -p 5000:5000 flaskapp python app.py
  • the app is now running on the VM. visit the app on the IP address from earlier, port 5000 (e.g. 192.168.99.100:5000)

all done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment