Skip to content

Instantly share code, notes, and snippets.

@Filirom1
Last active October 15, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Filirom1/e3ab5c361425abd98a62e35d6152150b to your computer and use it in GitHub Desktop.
Save Filirom1/e3ab5c361425abd98a62e35d6152150b to your computer and use it in GitHub Desktop.
A `docker run` that would stay attached when containers restart.
#!/usr/bin/env ruby
# This script is equivalent to a `docker run` that would stay attached when containers restart.
require 'open3'
require 'time'
cmd = ["/usr/bin/docker", "run", "-d"] + ARGF.argv
Open3.popen3(*cmd) do |stdin, stdout, stderr, thread|
puts stderr.read
exit_status = thread.value
if exit_status != 0
return exit exit_status.to_i
end
id = stdout.read.strip
puts id
loop do
last = Time.now
system "docker wait #{id}"
curr = Time.now
diff = curr - last
if diff < 1
exit -1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment