Giter VIP home page Giter VIP logo

docker-python-mongodb's Introduction

python-with-flask--Manual Process

Pre-Requisites

Install python
Install pip
Install Virtualenv

Install python and pip

yum install python-pip -y

Install Virtualenv

pip install virtualenv

Create virtual environment for application

virtualenv helloworld

Activate virtual environment

Windows machine

source helloworld/Scripts/activate

Linux Machine

source helloworld/bin/activate

Run requirements for flask applicaiton using below command

pip install -r requirements.txt

Run application

python application.py

With Docker file:

clone this module into your machine

git clone https://github.com/logambigaik/python-mongodb.git

Install docker

yum install -y docker

Start the service

service start docker

pull mongo:latest image

docker pull mongo:latest

Check Dockerfile for python application and requirements.txt

(Ref app.py for html template and application.py for json)

Check docker-compose.yml(for volume and dockerfile location)

install docker-compose:

sudo curl -L "https://github.com/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

         [root@ip-172-31-18-154 ~]# echo $PATH

          /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

docker-compose --version

If not worked try,
==============

yum install -y python3-pip

pip3 install docker-compose   

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

docker-compose --version

Build the docker-compose:

docker-compose build   

#Run the container :

docker-compose up

or docker-compose up -d

and push the image docker-compose push

After execution :

image

image

image

To remove the container:

docker-compose down

With docker run:

docker run --name mongodb -p 27017:27017 -d mongo:latest

docker run --name p1 --link mongodb:mongodb -p 5000:5000 python-mongodb_web:latest

[root@ip-172-31-15-216 python-mongodb]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

d956fa5a935b python-mongodb_web:latest "python app.py" 2 minutes ago Up 2 minutes 0.0.0.0:5000->5000/tcp p1

e86f0685cfc1 mongo:latest "docker-entrypoint.sā€¦" 3 minutes ago Up 3 minutes 0.0.0.0:27017->27017/tcp mongodb

image

After run:

image

Docker stack:

docker stack deploy --compose-file docker-compose.yml pymongo

image

Adding Node:

image

Services running in master:

image

image

Services runnng in slave:

image

image

Default docker network:

image

Changing network to this application:

    For creating network :
    
        docker network create pymongo-bridge --driver=bridge
        
        docker network create pymongo-overlay --driver=overlay

image

Docker compose with network:

image

image

Docker ps after compose up:

image

image

Adding node:

docker swarm join-token worker  -> in master and run the belwo token in node

   docker swarm join --token SWMTKN-1-0cyoevf5au6nym9047gxr42bzxghps7bdauu2egys3ehvj1z42-4pn23d0n58vebflofbqezxxwt 172.31.32.71:2377

image

Docker stack with bridge network:

  docker-compose push

REMOVED NETWORK NAME IN DOCKERSTACK-COMPOSE.YML

image

image

After updating network as overlay:

image

image

master:

image

node:

image

For monitoring:

https://docs.docker.com/config/daemon/prometheus/

docker service create --replicas 1 --name my-prometheus \
    --mount type=bind,source=/tmp/prometheus.yaml,destination=/etc/prometheus/prometheus.yml \
    --publish published=9090,target=9090,protocol=tcp \
    prom/prometheus
    

/etc/docker/daemon.json

{
  "metrics-addr" : "3.143.242.136:8000",
  "experimental" : true
}

cat /tmp/prometheus.yaml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'codelab-monitor'

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

rule_files:
  # - "first.rules"
  # - "second.rules"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['3.143.242.136:9090']

  - job_name: 'docker'
         # metrics_path defaults to '/metrics'
         # scheme defaults to 'http'.
    metrics_path: /prometheus
    static_configs:
      - targets: ['3.143.242.136:8000']

docker service create --replicas 1 --name my-prometheus \
   --mount type=bind,source=/tmp/prometheus.yaml,destination=/etc/prometheus/prometheus.yml \
   --publish published=9090,target=9090,protocol=tcp \
   prom/prometheus

docker-python-mongodb's People

Contributors

logambigaik avatar naresh240 avatar balu743tcs avatar

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.