generate init configuration file (systemd/Upstart) from docker-compose.yml
Project description
The dc2service utility generates configuration files for systemd/Upstart based on a single docker-compose YAML input file.
The init type is autodetected, but can be overruled from the commandline.
The service name is determinted by the container_name entries for all the services in the YAML file. Each service has to have a container_name specified.
As docker-compose YAML 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 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 doing dc2service templates
Example input YAML file for Mongo DB
docker-compose.yml file 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:27017
systemd
The command dc2service --systemd generate /opt/docker/mongo/docker-compose.yml will 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.target
Upstart
The command dc2service --upstart generate /opt/docker/mongo/docker-compose.yml will 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 script
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ruamel.dc2service-0.2.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd35e0fe8e84f5e9392c447f8c44426742298beba48e6b395f8902605b96d0bc |
|
MD5 | bb267684d3c89864c07fa38b5c9d3da2 |
|
BLAKE2b-256 | 03c6e20ac27665dc9eb9fed6e9455d7b283f2a75d8de6b4719843efe4383cefe |