Skip to content

Dockerize a simple Flask based rest api service that can be accessed from outside container

License

Notifications You must be signed in to change notification settings

krmanish/sample-docker-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sample-docker-app

Dockerize a sample Flask app that can be accessed from outside container.

Prereqsites

  1. Works best on Linux Distro. tested with Fedora 29
  2. Should have docker installed
  3. Should have python3 and all its required packages such as pip, flask etc. installed

Setup & Run

  • git clone https://github.com/krmanish/sample-docker-app

  • cd sample-docker-app

  • python3 apps.py # Verify if server running fine at http://0.0.0.0:5000. Kill this if all is well

  • Next Build container / Create Image: sudo docker build --tag sample-flask-app .

  • Finally create container & Run: sudo docker run --name sample-flask-app -p 5000 --expose 5000 sample-flask-app

That's it, if all goes well, you should be able to see a server running at http://172.17.0.2:5000 or something similar ip.

Test Cases & Coverage

  • Run testcase using coverage command coverage run -m pytest test_apps.py

  • Check out the testcase coverage coverage report test_apps.py

Test container app using CURL

  • curl -X GET http://<container ip address>:5000/hello
  • curl -X GET http://<container ip address>:5000/ack/hello-world
  • curl -X POST http://<container ip address>:5000/postme -d '{"foo": "wah", "bar": 12}' -H 'content-type: application/json'

Other Useful Docker commands

  • Show list of images: sudo docker images
  • Remove image: sudo docker image rm <image_name>
  • Show Running container: sudo docker ps
  • Remove Container: sudo docker rm sample-flask-app [or use container id]
  • Kill running container: sudo docker kill sample-flask-app [-f]

About

Dockerize a simple Flask based rest api service that can be accessed from outside container

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages