Last active
August 29, 2015 14:01
-
-
Save poppen/e1f7c332debc51ed321f to your computer and use it in GitHub Desktop.
Rakefile for Docker
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
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