Skip to content

ArcherHuang/Docker-Python-Flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How To Build and Deploy a Flask Application Using Docker on Ubuntu

Contents

Files

No Folder Comment
1 Script Install Docker package using this script
2 flask-sample Build an web app by using Python and Flask

Diagram

  • Flow
  • Scenario

Logging in to VM

  • On Local
    ssh VM-ACCOUNT@VM-IP
    

Install Docker Engine

  • On Local
    Download https://github.com/ArcherHuang/Docker-Python-Flask Repository
    
    cd to Docker-Python-Flask Repository
    
    scp ./Script/install-docker.sh VM-ACCOUNT@VM-IP:~
    
  • On VM
    cd ~
    
    chmod 777 install-docker.sh
    
    sudo ./install-docker.sh
    

Upload flask-sample to VM

  • On VM
    mkdir ~/flask-sample
    
  • On Local
    scp flask-sample/* VM-ACCOUNT@VM-IP:~/flask-sample
    

Build Docker Image

  • On VM
    cd ~/flask-sample
    
    sudo docker build -t mmosconii/docker-python:0.1 .
    

List Docker Image

  • On VM
    sudo docker images
    

Create Folder

  • On VM
    mkdir ~/dataset-out ~/model-out
    
    echo "hello" > ~/dataset-out/1.txt
    
    echo "world" > ~/model-out/2.txt
    

Add VM Port

  • On Chrome
    • Login Azure Portal from Browser > Click Networking > Click Add inbound security rule > Click Destination port ranges > Input 80 > Click Add

Run Docker Image

  • On VM
    sudo docker run -d -p 80:80 --name=test-dev -v ~/dataset-out:/dataset -v ~/model-out:/model mmosconii/docker-python:0.1
    

Check Docker Container

  • On VM
    sudo docker ps -a
    

Check API from Browser

Docker Container Log

  • On VM
    sudo docker logs -f test-dev
    

Into the Container

  • On VM
    sudo docker exec -it test-dev bash
    

Use Postman to Check API

Copy a file from Container to VM

  • On VM
echo "Lucky seven" > ~/filename.txt

sudo docker ps -a

sudo docker cp CONTAINER-ID:/app/filename.txt ~/777.txt

Copy a file from VM to Container

sudo docker ps -a

sudo docker cp ~/filename.txt CONTAINER-ID:/app/filename.txt 

Stop Container

  • On VM
    sudo docker ps -a
    
    sudo docker stop CONTAINER-ID
    

Remove Container

  • On VM
    sudo docker ps -a
    
    sudo docker rm CONTAINER-ID
    

Remove Docker Image

  • On VM
    sudo docker image prune -a
    

Contributor

Blog

License

This sample is licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published