The docker-compose.yml file¶

In order to do something useful with containers, they have to be arranged aspart of a project, usually referred to as an ‘application’. This is what adocker-compose.yml file does, specifying what images are required, whatports they need to expose, whether the have access to the host filesystem, whatcommands should be run, and so on.

Important

In the Divio Cloud architecture, the docker-compose.yml file is notused for Cloud deployments, but only for the local server. On the Cloud,the deployment is taken care of by dedicated systems on our servers.

The docker-compose.yml in Divio Cloud projects builds a web service ina container using its Dockerfile. It also builds a db service, from astandard postgres:9.4 image.

Most Divio Cloud projects will use this docker-compose.yml, or somethingvery similar to it.

  1. web:
  2. build: .
  3. links:
  4. - "db:postgres"
  5. ports:
  6. - "8000:80"
  7. volumes:
  8. - ".:/app:rw"
  9. - "./data:/data:rw"
  10. command: python manage.py runserver 0.0.0.0:80
  11. env_file: .env-local
  12. db:
  13. image: postgres:9.4
  14. volumes:
  15. - ".:/app:rw"

The first definition in the file is for the web service. In order, thedirectives mean:

  • build: build it from the Dockerfile in the parent directory
  • links: link to the database container
  • ports: map the external port 8000 to the internal port 80
  • volumes:
    • map the parent directory on the host to /app in the container, withread and write access
    • map the data directory on the host to /data in the container,with read and write access
  • command: by default, when the command docker-compose run is issued,execute python manage.py runserver 0.0.0.0:80
  • env_file: use the .env-local to supply environment variables to thecontainer
    The second definition is for the db service. On the Cloud, the project’sdatabase runs on an AWS server; locally, it runs on a Postgres instance indb.

The directives mean:

  • image: build the container from the postgres:9.4 image
  • volumes: map the parent directory on the host to /app in thecontainer, with read and write access
    See Expose the database’s port for an example of adding configuration todocker-compose.yml.

原文: http://docs.divio.com/en/latest/reference/docker-docker-compose.html