Hey · IT Guy!

HOME Archive Tags GITHUB ABOUT RSS

Docker-learning06/Docker Compose installation and deployment

2014-04

Docker-compose is easy to install and deployment , Please refer to the following steps below.

  1. Install Docker Engine version 1.7.1 or greater:

$curl -L https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
or 
$pip install docker-compose
</code>

2. On this page you build a simple Python web application running on Compose. The application uses the Flask framework and increments a value in Redis.
   While the sample uses Python, the concepts demonstrated here should be understandable even if you’re not familiar with it. 
   
Create a directory for the project:


mkdir composetest
jimmy@Coreos01:~/composetest$ tree -a
.
├── app.py
├── docker-compose.yml
├── Dockerfile
└── requirements.txt
0 directories, 4 files
jimmy@Coreos01:~/composetest$ cat app.py 
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
    redis.incr('hits')
    return 'Hello World! I have been seen %s times.' % redis.get('hits')
if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)
jimmy@Coreos01:~/composetest$ cat docker-compose.yml 
web:
  build: .
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis
jimmy@Coreos01:~/composetest$ cat Dockerfile 
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py
jimmy@Coreos01:~/composetest$ cat requirements.txt 
flask
redis
</code>
3. Build the image
$ docker build -t web .
jimmy@Coreos01:~/composetest$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
web                      latest              2e7cb752a718        33 minutes ago      682 MB
composehaproxyweb_weba   latest              04fb79e8f011        2 weeks ago         675.2 MB
composehaproxyweb_webb   latest              04fb79e8f011        2 weeks ago         675.2 MB
composehaproxyweb_webc   latest              04fb79e8f011        2 weeks ago         675.2 MB
4. Build and run your app with Compose
 docker-compose  up
Pulling redis (redis:latest)...
latest: Pulling from library/redis
c950d63587be: Pulling fs layer
Successfully built 3131aa500109
Creating composetest_web_1
Attaching to composetest_redis_1, composetest_web_1
5. check the web app:
jimmy@Coreos01:~$ docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
e38d83e3247c        composetest_web     "/bin/sh -c 'python a"   9 minutes ago       Up 9 minutes        0.0.0.0:5000->5000/tcp   composetest_web_1
[jimmy@oc3053148748 Desktop]$ curl -L http://192.168.122.241:5000
Hello World! I have been seen 7 times.[jimmy@oc3053148748 Desktop]$ 
Docker-compose-getting-started