Created
April 23, 2013 14:10
-
-
Save mharris717/5443865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mharris_ext' | |
#CONTAINER_ID=$(docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done") && echo $CONTAINER_ID | |
module Docker | |
class Instance | |
include FromHash | |
fattr(:commands) { [] } | |
attr_accessor :container_id | |
def run_str | |
"docker run -d base /bin/sh -c #{command_str}" | |
end | |
def full_str | |
"CONTAINER_ID=$(#{run_str}) && echo $CONTAINER_ID" | |
end | |
def command_str | |
'"' + commands.join(" && ") + '"' | |
end | |
def start! | |
self.container_id = ec full_str | |
end | |
def add_apt_install(*args) | |
str = args.flatten.join(" ") | |
self.commands << "DEBIAN_FRONTEND=noninteractive apt-get install -y -q #{str}" | |
end | |
end | |
end | |
d = Docker::Instance.new | |
#d.commands << "while true; do echo hello world; sleep 1; done" | |
d.add_apt_install "ruby1.9.1" | |
d.commands << "ruby -e 'puts :abc'" | |
puts d.full_str | |
d.start! | |
puts "ID: #{d.container_id}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment