Docker client library to access the Docker remote API.
Add this line to your application's Gemfile:
gem 'docker-client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install docker-client
Ready to be used with Docker version 0.4.0.
So far only the containers resource is supported. The images resource and endpoints in category misc according to the Docker Remote API documentation are not yet implemented (wip: see pull request)
require'docker'require'awesome_print'docker=Docker::API.new(base_url: 'http://localhost:4243')containers=docker.containers# Create a new containerresult=containers.create(['/bin/sh','-c','while true; do echo hello world; sleep 1; done'],'base')container_id=result["Id"]apresult# Start created containercontainers.start(container_id)# Get container details (inspect)details=containers.show(container_id)apdetails# Get file system changes of containerchanges=containers.changes(container_id)apchanges# Attach to container for 3 secondsoptions={stdout: true,stderr: false}containers.attach(container_id,options,3)do |data|
puts">> #{data}"end# Get all output since container is startedoutput=containers.logs(container_id)apoutput# List all running containersrunning_containers=containers.listaprunning_containers# Stop containercontainers.stop(container_id)# Remove containercontainers.remove(container_id)All tests are stubbed with VCR. You can edit the setting config.default_cassette_options in spec_helper.rb to run the tests against the docker API. Set it to {:record => :all}. This will alos re-record all VCR request/response. To run the tests stubbed again uncomment the before mentioned setting.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
MIT License. Copyright 2013 Georg Kunz.