Skip to content

Instantly share code, notes, and snippets.

@bfulton
Created June 28, 2014 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bfulton/a597ca309c24b94b318d to your computer and use it in GitHub Desktop.
Save bfulton/a597ca309c24b94b318d to your computer and use it in GitHub Desktop.
require 'docker'
container = Docker::Container.create(
'Image' => 'ubuntu:latest',
'Cmd' => [
'/bin/bash',
'-c',
'for i in {1..10}; do echo $i; sleep 1; done'
]
)
container.tap(&:start).attach do |stream, chunk|
puts "#{Time.now.inspect}: #{stream}: #{chunk}"
end
## should print something like:
# 2014-06-28 10:14:20 -0400: stdout: 1
# 2014-06-28 10:14:21 -0400: stdout: 2
# 2014-06-28 10:14:22 -0400: stdout: 3
# 2014-06-28 10:14:23 -0400: stdout: 4
# 2014-06-28 10:14:24 -0400: stdout: 5
# 2014-06-28 10:14:25 -0400: stdout: 6
# 2014-06-28 10:14:26 -0400: stdout: 7
# 2014-06-28 10:14:27 -0400: stdout: 8
# 2014-06-28 10:14:28 -0400: stdout: 9
# 2014-06-28 10:14:29 -0400: stdout: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment