Skip to content

logambigaik/docker-python-mongodb

 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 72.0%
  • HTML 25.3%
  • Dockerfile 2.7%