Coder Social home page Coder Social logo

docker-compose-api's Introduction

Build Status Code Climate Test Coverage Gem Version Dependency Status

Docker Compose Api

Docker Compose API provides an easy way to parse docker compose files and lift the whole environment.

Instalation

Install the gem in whole environment

gem install docker-compose-api

... or using Bundler

# Add the line below on your Gemfile...
gem 'docker-compose-api'

# ... and run bundle install
bundle install

Usage

require 'docker-compose'

# Docker compose is simply a layer running over Docker client (https://github.com/swipely/docker-api).
# So, all Docker specific configurations, such URL, authentication, SSL, etc, must be made directly on
# Docker client.
#
# Docker compose provides an easy way to access this client:
DockerCompose.docker_client

# Gem version
DockerCompose.version

# Loading a compose file
compose = DockerCompose.load('[path to docker compose file]')

# 'Load' method accepts a second argument, telling to do load or not
# containers started previously by this compose file.
#
# So, loading a compose file + containers started by this compose previously
compose = DockerCompose.load('[path to docker compose file]', true)

# Accessing containers
compose.containers                                   # access all containers
compose.containers['container_label']                # access a container by its label (DEPRECATED)
compose.get_containers_by(label: 'foo', name: 'bar') # Returns an array of all containers with label = 'foo' and name = bar

# Containers names are generated using the pattern below:
#  [Directory name]_[Container label]_[Sequential ID]
#
# So, you can access a container by its full name...
compose.get_containers_by(name: 'myawessomedir_foobar_1')

# ... or by its given name (ignores both prefix and suffix)
compose.get_containers_by_given_name('foobar')

# Starting containers (and their dependencies)
compose.start                                    # start all containers
compose.start(['container1', 'container2', ...]) # start a list of specific containers

# Stopping containers
# (ps: container dependencies will keep running)
compose.stop                                    # stop all containers
compose.stop(['container1', 'container2', ...]) # stop a list of specific containers

# Killing containers
# (ps: container dependencies will keep running)
compose.kill                                    # kill all containers
compose.kill(['container1', 'container2', ...]) # kill a list of specific containers

# Deleting containers
# (ps: container dependencies will keep running)
compose.delete                                    # delete all containers
compose.delete(['container1', 'container2', ...]) # delete a list of specific containers

# Checking if a container is running or not
a_container = compose.get_containers_by(name: 'a_container').first
a_container.running?

# Accessing container informations
a_container.stats

Contributing

  1. Fork it ( https://github.com/mauricioklein/docker-compose-api/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

docker-compose-api's People

Contributors

cpuid avatar jeroenj avatar mauricioklein avatar rgarbin avatar zuazo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.