Skip to content

sugi/sshkit-backend-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Docker connector backend for SSHKit

Resources

License

Stars

Watchers

Forks

Packages

No packages published