No commit activity in last 3 years
No release in over 3 years
sshkit-backend-docker provides Docker connection and some utilities. You can execute commands inside docker container without ssh connection.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.9.0
 Project Readme

SSHKit::Backend::Docker

Gem Version

Docker connector backend for SSHKit. You can execute commands inside docker container without ssh connection.

If you use capistrano, please refer capistrano-deploy_into_docker.

Installation

Add this line to your application's Gemfile:

gem 'sshkit-backend-docker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sshkit-backend-docker

Usage

Currently, you need to set SSHKit.config.backend to run command with docker backend.

SSHKit.config.backend = SSHKit::Backend::Docker

Host definitions

SSHKit::Backend::Docker extends SSHKit::Host. You can specify docker environemnt as Hash. The hash requires :image (or :container) key to run.

host = SSHKit::Host.new(docker: {image: 'ruby:slim'})

In addtion, you can add any options for "docker run" via docker_run_image. for example;

host = SSHKit::Host.new(docker: {
    image: 'sugi/rails-base:latest',
    commit: 'new-image-name:tag',
    volume: ['/storage/tmp:/tmp', '/storage/home:/home'],
    network: 'my-net',
    dns: '8.8.8.8',
    dns_search: 'example.com',
    cap_add: ['SYS_NICE', 'SYS_RESOURCE'],
  }, user: 'nobody:nogroup')

DSL

  • docker_commit - Commit running container as image. In default :commit key of host will be used. You can pass argument to override. Currently this DSL method can commit container which is ran by SSHKit::Backend::Docker from image.
  • docker_run_image - In useal case, Docker container will start automatically when execute command. However you can run any image intentionally by docker_run_iamge.

Examples

require 'sshkit'
require 'sshkit-backend-docker'
include SSHKit::DSL

SSHKit.config.backend = SSHKit::Backend::Docker

host = {docker: {image: 'ruby:slim'}}

on [host] do
   execute :ls
   upload! '/etc/passwd', '/etc/passwd'
   docker_commit 'my-new-image'
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sugi/sshkit-backend-docker.

Copyright

2016 Tatsuki Sugiura, this library is distributed MIT License.