Skip to content

starlord-daniel/flask-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flask-rest

A RESTful service based on the Flask Python framework

Docker Container

This setup requires Docker to run on your PC. I've used Windows and Powershell to run the commands. You can find the downloads for Windows and Mac at the respective links.

The Create an image from the Flask service and run it and upload it as a web service, follow these steps:

Build the image by running:

docker build -t <image-name> .

Where -t is used to set the tag for the image to create. The dot (.) at the end refers to the file path of the Dockerfile. For the build to work, the whole path can't contain any spaces. Something like C:\test would be fine, but "C:\test\this app" wouldn't be.

An example:

docker build -t flask-rest .

Run the container locally:

docker run -p 8000:8000 <image-name>

The property -p sets the port mapping for the container. As the script exposes port 8000, this should be mapped to another port of the container. You might change the second value (right) to change the port to speak to.

An example:

docker run -p 8000:8000 flask-rest

[Option 1/2] Upload image to Docker Hub:

  1. Login to docker from command line

    docker login --username <docker-id> --password <docker-hub-password>
    

    It is more secure, to use --password-stdin to login to your docker account:

    $ cat ~/my_password.txt | docker login --username foo --password-stdin
    

    More information can be found in the Docker Docs

  2. Push the image to Docker Hub:

    docker push <docker-id>/<name-of-image>:v1.0.0 .
    

[Option 2/2] Upload image to Azure Container Registry

  1. Prepare for upload:

    pip install --user azure-cli

    If this doesn't work, download the installer and follow the instructions up on Azure Docs

  2. Login to your container registry:

    docker login <acr-name>.azurecr.io 
    
  3. Push to your registry:

    docker tag <image-name> <acr-name>.azurecr.io/<repo-name>
    docker push awesome.azurecr.io/<repo-name>
    

    More info in the Azure Docs

Create a web service from your Docker image

This chapter is in development.

Releases

No releases published

Packages

No packages published

Languages