Create docker container with the simple flask application

I will try to create a docker container with the simple flask application created some times ago.



First, I create a shell script for starting the flask application, namely "boot.sh":

boot.sh
#!/bin/sh
export FLASK_APP=simple.py
flask run --host 0.0.0.0



Second, we need to create a requirements.txt file:

requirements.txt
flask==1.1.1

Actually you can run the following to get the requirements.txt:

pip freeze > requirements.txt



Third, together with the simple.py file created in the simple flask application, put those 3 files in an "app" directory:

app/
   - boot.sh
   - requirements.txt
   - simple.py



Forth, create a Docker file outside the app directory:

Dockerfile
FROM python:3.6-alpine
WORKDIR /home/app
COPY app/ ./
RUN chmod +x ./boot.sh
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]

Build the docker image using the Dockerfile:

     docker build -t simple:latest .

Run the docker container with the docker image we just created:

     docker run -d -p 5000:5000 simple:latest

Check "http://localhost:5000" to check the Flask application.

Comments

Popular posts from this blog

Java encoding : UTF-8, Big5, x-MS950-HKSCS