Docker use compose (formerly Fig) fast allocation

Docker use compose (formerly Fig) fast allocation

table of Contents

installation

Fig installed on Linux:
installation on OS:

Fig installed on Linux:

sudo bash-c "curl -L https://github.com/docker/fig/releases/download/0.5.2/darwin "

chmod +x /usr/local/bin/fig

On the OS installation:

curl -L https://github.com/docker/fig/releases/download/0.5.2/darwin > /usr/local/bin/fig

chmod +x /usr/local/bin/fig

View Results:

fig --version

Docker company also provides allocation tools compose (formerly Fig) used to construct accelerated Docker environment.

pip install docker-compose

application

Using as an example two containers:

  • Application of the container, running the sample program Python
  • Redis container, run Redis database

Create a directory and create Dockerfile,

mkdir figapp
cd figapp
touch Dockerfile

Create a file called app.py, and write the code listing, the code is as follows:

app.py:

from flask import Flask
from redis import Redis
import os
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)

Requirements.txt also you need to create a file to hold the application's dependencies.

flask
redis

Finally add Dockerfile contents of the file:

FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt

File-based python: 2.7 mirrored building.
First app.py add files to the mirror and requirements.txt in / figapp directory.
After Dockerfile the working directory to / figapp, and execute the command to install the application pip dependency:
the Flask and redis

Construction of Mirror

cd figapp
docker build -t="taiyangyixi2/figapp"

View Mirror

docker images

Define Service

Create a docker-compose.xml file

web:
  build: .
  command: python app.py
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis

Build and run

Construct:

docker-compose up

run:

docker-compose run web env

stop:

docker-compose stop

References

Fast allocation

Guess you like

Origin www.cnblogs.com/zhichun/p/11878991.html