./rocker # will create a container named default from the Dockerfile
./rocker foo # will create a container named foo from the Dockerfile
Last active
January 3, 2016 15:19
-
-
Save ranjib/8482470 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FROM ubuntu | |
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list | |
RUN apt-get update | |
RUN apt-get install -y x11vnc xvfb firefox | |
RUN mkdir /home/ubuntu/.vnc | |
RUN x11vnc -storepasswd 1234 /home/ubuntu/.vnc/passwd | |
RUN bash -c 'echo "firefox" >> /home/ubuntu/.bashrc' |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'lxc' | |
class Docker2LXC | |
attr_reader :ct | |
def initialize(name) | |
@ct = LXC::Container.new name | |
end | |
def from(template) | |
ct.create(template) | |
ct.start | |
puts "Successfully created container, starting it, sleeping for 5 seconds till the container get ip" | |
sleep 5 | |
end | |
def run(*args) | |
env = {'PATH'=>'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | |
'USER' => 'root', 'HOME'=>'/root' } | |
command = args.join(' ') | |
puts "Executing: '#{command}'" | |
ret = ct.attach(wait: true) do | |
pid = spawn(env, command, :unsetenv_others=>true) | |
Process.wait pid | |
end | |
puts "Exit code :#{ret}" | |
end | |
def expose(ct_port, host_port=nil) | |
host_port = ct_port if host_port.nil? | |
# setup ip tables port forwarding here, using chef or pupper or raw spawn | |
end | |
def self.build(name) | |
d = Docker2LXC.new(name) | |
File.readlines('Dockerfile').each do |line| | |
code_line = line.sub(/\#.*^/,'').strip | |
next if code_line.empty? | |
method, *args = code_line.split(/\s+/) | |
d.send(method.downcase.to_sym, *args) | |
end | |
end | |
end | |
if $0 == __FILE__ | |
name = ARGV.empty? ? 'default' : ARGV.first | |
Docker2LXC.build(name) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment