Skip to content

Instantly share code, notes, and snippets.

@poppen
Last active August 29, 2015 14:01
Show Gist options
  • Save poppen/e1f7c332debc51ed321f to your computer and use it in GitHub Desktop.
Save poppen/e1f7c332debc51ed321f to your computer and use it in GitHub Desktop.
Rakefile for Docker
builder_name = ''
image_name = ''
publish_port = ''
expose_port = ''
tag = "#{builder_name}/#{image_name}"
if ENV['version']
tag += ":#{ENV['version']}"
end
desc "run"
task :run do |t|
port = ENV['port'] || publish_port
begin
sh "docker stop #{image_name}"
sh "docker rm #{image_name}"
rescue => e
puts e
end
sh "docker run --name #{image_name} -p #{port}:#{expose_port}: -d #{tag}"
end
desc "build"
task :build do |t|
sh "docker build -t #{tag} ."
end
desc "shell"
task :shell do |t|
sh "docker run --rm -i -t #{tag} /bin/bash"
end
desc "ssh"
task :ssh do |t|
ipaddr = `docker inspect --format='{{.NetworkSettings.IPAddress}}' "#{image_name}"`
sh "ssh root@#{ipaddr}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment