-
Notifications
You must be signed in to change notification settings - Fork 290
Open
Description
Hi all,
When I start up a container and attach an stdin to it, the container hangs forever waiting for input.
I've made a minimal reproducible example that consistently fails on OSX, but not in Linux:
require 'docker'
image_name = 'alpine'
docker_options = {
Cmd: ['cat'],
Image: image_name,
name: "image-#{SecureRandom.urlsafe_base64(10)}", # assuming unique during execution
OpenStdin: true,
}
container = Docker::Container.create(**docker_options)
outlines, errlines = container.tap(&:start).attach(
stdin: StringIO.new('this should come out again\r\n\r\n\n'),
stdout: true,
stderr: true
)
puts outlines
puts errlinesI'm not entirely sure what's going wrong, for example, this example shows that reading and forwarding stdout back to the host just works fine (returns test):
require 'docker'
image_name = 'alpine'
docker_options = {
Cmd: ['sh', '-c', 'sleep 1 && echo test'],
Image: image_name,
name: "image-#{SecureRandom.urlsafe_base64(10)}", # assuming unique during execution
}
container = Docker::Container.create(**docker_options)
outlines, errlines = container.tap(&:start).attach(
stdout: true,
stderr: true
)
puts outlines
puts errlinesSo it seems as if the stdin is never forwarded correctly to the container.
With a debug log:
D, [2025-12-15T17:16:49.766699 #6159] DEBUG -- : [:post, "/containers/create", {:name=>"image-z4_41eA0l0QVYg"}, "{\"Cmd\":[\"cat\"],\"Image\":\"alpine\",\"OpenStdin\":true}"]
D, [2025-12-15T17:16:49.794568 #6159] DEBUG -- : [:post, "/containers/f878430c7750c4f01182514d16319843bbc3a31b5ba93ef62bd83cf92645a812/start", {}, "{}"]
D, [2025-12-15T17:16:49.853695 #6159] DEBUG -- : [:post, "/containers/f878430c7750c4f01182514d16319843bbc3a31b5ba93ef62bd83cf92645a812/attach", {:stream=>true, :stdout=>true, :stderr=>true, :stdin=>true}, nil]
D, [2025-12-15T17:16:49.854914 #6159] DEBUG -- : hijack: hijacking the HTTP socket
D, [2025-12-15T17:16:49.854933 #6159] DEBUG -- : hijack: starting stdin copy thread
D, [2025-12-15T17:16:49.854979 #6159] DEBUG -- : hijack: starting hijacked socket read thread
D, [2025-12-15T17:16:49.854993 #6159] DEBUG -- : hijack: copying stdin => socket
D, [2025-12-15T17:16:49.855122 #6159] DEBUG -- : hijack: reading from hijacked socket
D, [2025-12-15T17:16:49.855188 #6159] DEBUG -- : hijack: closing write end of hijacked socket
D, [2025-12-15T17:16:49.855224 #6159] DEBUG -- : hijack: closed write end of hijacked socket
Any ideas as to what might cause this?
Metadata
Metadata
Assignees
Labels
No labels