Last active
October 15, 2016 16:37
-
-
Save Filirom1/e3ab5c361425abd98a62e35d6152150b to your computer and use it in GitHub Desktop.
A `docker run` that would stay attached when containers restart.
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
#!/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