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.
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
Currently, you need to set SSHKit.config.backend
to run command with docker backend.
SSHKit.config.backend = SSHKit::Backend::Docker
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')
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 bydocker_run_iamge
.
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
Bug reports and pull requests are welcome on GitHub at https://github.com/sugi/sshkit-backend-docker.
2016 Tatsuki Sugiura, this library is distributed MIT License.