Package: ruamel.dc2service
Thedc2serviceutility generates configuration files forsystemd/Upstartbased on a singledocker-composeYAML input file.The init type is autodetected, but can be overruled from the command-line.The service name is determinted by thecontainer_nameentries for all
the services in the YAML file. Each servicehas to haveacontainer_namespecified.Asdocker-composeYAML file format doesn’t allow for
extra metadata fields, two comment entries at the beginning of the
YAML file are parsed for a description and author.If the version 2 YAML file format is used you should consider usingruamel.dcwas wrapper fordocker-compose, if you do the
comments are not necessary and you can specifyauthoranddescriptionunder the top leveluser-datakey.If external ports are specified (i.e. of the form “ip:ip”) then the
external port numbers are extended to the description.The file generation is template based and can easily be adjusted to your needs.
Their location can be viewed by doingdc2service templatesExample version 2 input YAML file for Mongo DBIn a version 1docker-compose.ymland usingruamel.dcwyou can set theauthoranddescriptionconveniently as normal
key-value pairs, and also specify a default for environment variables:version: "2"
user-data:
  author: Anthon van der Neut <a.van.der.neut@ruamel.eu>
  description: mongo container
  env-variables:
    DOCKER_MONGO_PORT: 27017
    DOCKER_MONGO_BASE_DIR: /data1/DB/mongo
services:
  mongodb:
    container_name: mongo
    image: mongo:2.4
    volumes:
      - ${DOCKER_MONGO_BASE_DIR}:/data/db
      ports:
        - ${DOCKER_MONGO_PORT}:27017Example version 1 input YAML file for Mongo DBAs version 1docker-compose.ymlfile for single service running
Mongo DB with an external (i.e. host oriented) port:# author: Anthon van der Neut <a.van.der.neut@ruamel.eu>
# description: mongo container
mongodb:
  container_name: mongo
  image: mongo:2.4
  volumes:
   - /data1/DB/mongo:/data/db
  ports:
  - 27017:27017systemdThe commanddc2service--systemdgenerate/opt/docker/mongo/docker-compose.ymlwill
generate the file/etc/systemd/system/mongo-docker.service:[Unit]
Description=mongo container on port 27017
# Author = Anthon van der Neut <a.van.der.neut@ruamel.eu> (dc2service 0.1.0.dev)
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/opt/util/docker-compose/bin/docker-compose -f /opt/docker/mongo/docker-compose.yml up --no-recreate
ExecStop=/opt/util/docker-compose/bin/docker-compose -f /opt/docker/mongo/docker-compose.yml stop

[Install]
WantedBy=multi-user.targetIf you haveruamel.dcwinstalled.../bin/docker-composewill be.../bin/dcwUpstartThe commanddc2service--upstartgenerate/opt/docker/mongo/docker-compose.ymlwill
generate the file/etc/init/mongo-docker.conf:description "mongo container on port 27017"
author "Anthon van der Neut <a.van.der.neut@ruamel.eu> (dc2service 0.1.0.dev)"
start on filesystem and started docker
stop on runlevel [!2345]
respawn

pre-start script
  /opt/util/docker-compose/bin/docker-compose -f /opt/docker/mongo/docker-compose.yml up -d --no-recreate
end script

script
  sleepWhileAppIsUp(){
    while docker ps --filter=name=mongo | grep -qF mongo ; do
      sleep 2
    done
  }

  sleepWhileAppIsUp
end script

post-stop script
  if docker ps --filter=name=mongo | grep -qF mongo; then
    /opt/util/docker-compose/bin/docker-compose -f /opt/docker/mongo/docker-compose.yml stop
  fi
end scriptIf you haveruamel.dcwinstalled.../bin/docker-composewill be.../bin/dcwExpanding environment variablesIf you use environment variables in a version 1 docker-compose.yml
file in your YAML file they will be expanded if the are of the form${XYZ}. The other form$XYZis not expanded. You should however
consider installingruamel.dcwand using the version 2 format as
that can handle the expansion dynamically and allow defaults to be
specified in the YAML file, as well as storing the environment variables for the
Dockerfile to use.Expansion is only relevant for the parts that are copied (external
port numbers, name of container).If you use this feature make sure that the environment variables are set in the
conf file. Insystemdwith:[Service]
Environment=DOCKERIMAPPORT=143and in Upstart:env DOCKERIMAPPORT=143dc2servicewill try to insert the right definitions for you.For version 2 files and when using ``ruamel.dcw`` this is not necessary and
therefore not doneFindingdocker-composeAs the full path todocker-composeordcwwill be inserted in
the configuration file, this path needs to be
available.dc2servicewill search/opt/util/docker-compose/bin/and the PATH environement variable
for the locations ofdcwanddocker-compose. If yourdocker-composeis not in your path you can hand the full path in
with the option--docker-composeor specify this in the file~/.config/ruamel_dc2service/ruamel_dc2service.pon:dict(
    glbl={'docker-compose': '/opt/util/docker-compose/bin/docker-compose'},
)