building application stacks

Connecting the dots

python

webapp

redis

launch apps

docker container run -idt --name redis redis:alpine
1:C 02 Feb 15:26:00.798 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/t
o/redis.conf                                                                                                                                     
                _._                                                                                                                              
           _.-``__ ''-._                                                                                                                         
      _.-``    `.  `_.  ''-._           Redis 3.2.7 (00000000/0) 64 bit                                                                          
  .-`` .-```.  ```\/    _.,_ ''-._                                                                                                               
 (    '      ,       .-`  | `,    )     Running in standalone mode                                                                               
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379                                                                                               
 |    `-._   `._    /     _.-'    |     PID: 1                                                                                                   
  `-._    `-._  `-./  _.-'    _.-'                                                                                                               
 |`-._`-._    `-.__.-'    _.-'_.-'|                                                                                                              
 |    `-._`-._        _.-'_.-'    |           http://redis.io                                                                                    
  `-._    `-._`-.__.-'_.-'    _.-'                                                                                                               
 |`-._`-._    `-.__.-'    _.-'_.-'|                                                                                                              
 |    `-._`-._        _.-'_.-'    |                                                                                                              
  `-._    `-._`-.__.-'_.-'    _.-'                                                                                                               
      `-._    `-.__.-'    _.-'                                                                                                                   
          `-._        _.-'                                                                                                                       
              `-.__.-'                                                                                                                           
                                                                                                                                                 
1:M 02 Feb 15:26:00.804 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower val
ue of 128.                                                                                                                                       
1:M 02 Feb 15:26:00.804 # Server started, Redis version 3.2.7                                                                                    
1:M 02 Feb 15:26:00.804 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.o
vercommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.            
1:M 02 Feb 15:26:00.804 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage
 issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc
/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.                                          
1:M 02 Feb 15:26:00.804 * The server is now ready to accept connections on port 6379              

launch apps

docker container  run -idt  --name vote -P  schoolofdevops/vote

Try registering a vote through webapp 
docker container rm -f vote

link

docker container  run -idt  --name vote --link redis:redis -P  schoolofdevops/vote

redis:redis

redis

redis

vote

link

docker container  run -idt  --name worker --link redis:redis -P  schoolofdevops/vote-worker


docker logs worker
root@docker2-2gb-nyc3-01:/workspace# docker logs worker                                                                                          
Connected to redis                                                                                                                               
Waiting for db                                                                                                                                   
Waiting for db                                                                                                                                   
Waiting for db                                                                                                                                   
Waiting for db                                                                                                                                   
Waiting for db                                 

vote

redis

worker

docker-compose.yml

compose file

V1

vote:
  build: ./vote
  command: python app.py
  links:
    - redis:redis
  ports:
    - 80

redis:
  image: redis:alpine

worker:
  build: ./worker
  dockerfile: Dockerfile
  links:
    - redis:redis
docker-compose.yml

config check

docker-compose config 

build images

docker-compose build 

docker-compose build ( observe caching ) 

launch with compose

docker-compose up -d 

docker-compose ps


docker rm -f vote redis worker

additional commands

docker-compose  images

docker-compose logs

docker-compose logs  worker

docker-compose pull

docker-compose exec vote ps


docker-compose stop 

docker-compose down
version: "3.0"

networks:
  vote:
    driver: bridge

services:
  vote:
    build: ./vote
    command: python app.py
    networks:
      - vote
    ports:
      - 80
    depends_on:
      - redis

  redis:
    image: redis:alpine
    networks:
      - vote

  worker:
    build:
      context: ./worker
      dockerfile: Dockerfile
    networks:
      - vote
    depends_on:
      - redis
vote:
  build: ./vote
  command: python app.py
  links:
    - redis:redis
  ports:
    - 80

redis:
  image: redis:alpine

worker:
  build: ./worker
  dockerfile: Dockerfile
  links:
    - redis:redis

docker-compose.yml

docker-compose-v3.yml

docker-compose -f docker-compose-v3.yml up -d 


docker-compose -f docker-compose-v3.yml ps


docker-compose -f docker-compose-v3.yml down

Launching Stack

updating stack

db
image:   postgres:9.4

volumes

db-data
volumes:  
db-data:/var/lib/postgresql/data
networks:   vote
image:   schoolofdevops/vote-result
networks:   vote
ports:   5001:80

SERVICES

result

https://gist.github.com/initcron/162f15c3ca822551bfbbe3f634d681aa

Docker Compose File

Copy of D 106: Deploying Micro Services with Docker Compose

By School of Devops

Copy of D 106: Deploying Micro Services with Docker Compose

Docker - Connecting the Dots with Compose

  • 1,139