mobile ecommerce development

How to create a simple flask app in a docker container

Creating docker containers is a great way to separate your projects and quick to publish and others test the program

Step 1. Create a new folder

create a new python program to run a Flask app

@app.route("/")
def main(): return "Welcome to Docker images running on windows"

@app.route('/how are you')
def hello(): return 'I am good, how about you?'

if name == "main": app.run(host="0.0.0.0")

 

Step 2 Create a docker file

FROM ubuntu
RUN apt-get update && apt-get -y install python
RUN apt-get install python3-pip -y
RUN pip install flask flask-mysql
COPY . /opt
EXPOSE 5000
CMD ["python3", "/opt/app.py"]

Step 3 Build your container

On Docker Hub create free account to pubish your containers. 

docker build . -f dockerfile -t mcs4uweb/my-app

Step 4 List your images

Install the docker CLI to manage your containers and images. 

google docker cli

docker images

Step 5 Run the Docker container

docker run -p 5000:5000 70c9404d25b6

find your IP address and open the browser

use ifconfig to find your ip address

ipconfig

Windows IP Configuration IPv4 Address. . . . . . . . . . . : 192.168.1.152

in the browser

192.168.1.152:5000

Get in touch