Skip to main content

Package to generate docker compose files.

Project description

pydockercompose

Description

This package is a python package for generating Docker Compose file. It contains two classes :

  • DockerCompose : It represents docker-compose file. In this version, it supports adding the following parameters:
    • version
    • services
    • volumes
    • networks
  • Service: This class represent docker compose service. In this version, Service class supports adding the following parameters:
    • container_name
    • image
    • build
    • environment
    • restart
    • ports
    • volumes
    • networks
    • ulimits
    • links
    • depends_on
    • command
    • entrypoint
    • network_mode

To find out more about these parameters, you can check docker-compose documentation.

Usecase

In this example we used pydockercompose package to generate docker-compose.yml for :

  • ElasticSearch service

  • ElasticSearch Client service that will be built using Dockerfile.

      import pydockercompose
      import os,sys
    
      def generate_elastic_docker_compose_file():
          docker_compose = DockerCompose(version="3.3")
      
          # Create ElasticSearch service.
          elastic_svc = Service(container_name="es",
                                image="elasticsearch:7.13.3",
                                restart="on-failure",
                                ports=["9200:9200"],
                                networks=["es-network"],
                                volumes=["es-data:/usr/share/elasticsearch/data"],
                                environments=["discovery.type=single-node"])
          elastic_svc.set_ulimits("memlock", {"soft": -1, "hard": -1})
      
          # Create ElasticSearch Customer service.
          cmd = "while [ 1 -e 1 ]; do curl 'http://es:9200/' && sleep 3 ; done"
          with open("Dockerfile", "w") as dockerfile:
              dockerfile.write("FROM alpine:3\nRUN apk add curl\nCMD "+cmd)
          customer_svc = Service(container_name="es-customer",
                                 build=".",
                                 restart="on-failure",
                                 depends_on=["es"],
                                 networks=["es-network"])
      
          # Add services to DockerCompose object.
          docker_compose.add_service("es", elastic_svc)
          docker_compose.add_service("es-customer", customer_svc)
      
          # Add the network es-network
          docker_compose.add_network("es-network", {"driver": "bridge"})
      
          # Add the volume es-data
          docker_compose.add_volumes("es-data", {"driver": "local"})
          return docker_compose
      
      
      if __name__ == '__main__':
          generate_elastic_docker_compose_file().to_yaml()
          os.system("docker-compose up")
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydockercompose-0.1.0.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

pydockercompose-0.1.0-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page