Code Monkey home page Code Monkey logo

docker-flask-sample's Introduction

docker-flask-sample

Docker container with Python 2.7 and Flask (Sample from Get Started)

Alt text

This container was bringin from Docker Get Started Page. I added feature for checking and parsing user agent of visitors.

Libs Imported

  • Flask
  • pyyaml
  • ua-parser
  • user-agents

Usages

  1. Clone this image
  2. Run docker build -t <your_whathever_image_name> . (ended with dot)
  3. Run docker images to check images
  4. Run docker run -p 4000:80 <your_whathever_image_name> or docker run -d -p 4000:80 <your_whathever_image_name> to detached container on background
  5. Locate to http://localhost:4000 from your current browser

Want to stop? Run docker container stop $(docker container ls -a -q)

To Remove containers Run docker container rm $(docker container ls -a -q)

To see list of container running, use docker ps.

Service and Swarm

Docker has a service and swarms feature to demonstrate like load balancing over containers. You need to do is docker-compose.yml :

version: "3"
services:
  web:
    image: emsi_python_sample:latest
    deploy:
      replicas: 2
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:

I use local image for this project, you don't need a Docker Cloud account.

And then run this following commands to make it:

  1. Run docker swarms init to initialize swarms
  2. Then run docker stack deploy -c docker-compose.yml pythonproject to define a new service called pythonproject
  3. Run docker service ls to check running service

Alt text

  1. Because we ported the app into port 80, you can access this service through http://localhost:80 and Voila!
  2. Refresh it, and make sure container host ID is changed on every hit.

Thank you. And happy coding!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.