Saturday, December 9, 2017

docker-compose

Install docker-compose on CentOS. Digital Ocean tutorials are very good:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-centos-7


sudo yum install epel-release
sudo yum install -y python-pip


if you get

"Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
"

just do "ps -ef | grep PackageKit", find the PID and do "sudo kill -9 PID"


sudo pip install --upgrade pip

sudo pip install docker-compose
sudo yum upgrade python*


docker-compose



Awesome quick hands-on php tutorial on docker-compose



first do:
sudo pip3.6 install flask
sudo pip3.6 install flask_restful


cd
mkdir jakewright; cd jakewright
mkdir product; cd product

you should have this tree:
~
~/jakewright
~/jakewright/product

make sure you are in ~/jakewright/product :

cat api.py
from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class Product(Resource):
    def get(self):
        return {
            'products' : ['Ice Cream', 'Chocolate', 'Fruit']
        }

api.add_resource(Product, '/')

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9080, debug=True)

python3.6 api.py

http://localhost:9080/


cat Dockerfile
FROM python:3-onbuild
COPY . /usr/src/app
CMD ["python", "api.py"]



cat requirements.txt
flask
flask_restful


docker build . -t jakewright
-> Successfully tagged jakewright:latest
docker images
docker run -p 9080:9080 jakewright


now in ~/jakewright folder:
cat docker-compose.yml

version: '3'

services:
product-service:
build: ./product
volumes:
- ./product:/usr/src/app
ports:
- 9080:9080


(leaving the second part for now....)

docker-compose up -d
docker-compose stop

your service should now be equally available, in an image called jakewright_product-service


User Manual for Dockerfile https://docs.docker.com/engine/reference/builder/#usage



PS another GREAT video by Jake Wright is Learning CSS https://www.youtube.com/watch?v=0afZj1G0BIE , and don't forget Learning Docker https://www.youtube.com/watch?v=YFl2mCHdv24





No comments: