Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker STDOUT missing when using sinatra #1118

Closed
singram opened this issue May 28, 2016 · 4 comments
Closed

Docker STDOUT missing when using sinatra #1118

singram opened this issue May 28, 2016 · 4 comments

Comments

@singram
Copy link

singram commented May 28, 2016

Given the following simple example (app.rb) and nothing more

# -*- coding: utf-8 -*-
require 'sinatra'
set :bind, '0.0.0.0'
puts "WOOT a puts statement was HERE"
get '/' do
  "hello world"
end

Executing this via
bundle exec ruby app.rb
Renders both the puts statement and the expected sinatra behavior.

However when the same code is executed within a Docker container with the same execution command only the Sinatra output is visible. The puts statement never gets rendered.

However if you comment everything but the 'puts' statement and execute it in docker the puts statement is rendered correctly. The difference in docker behavior seems to be dependent on whether sinatra is required or not.

I seem to be missing something simple here. Any ideas?

@ghost
Copy link

ghost commented Jun 8, 2016

@singram I'm pretty sure this has to do with how IO is buffered in a docker container. If you add a puts "here" to the top of your snippet, you should find that both statements get printed.

@z2s8
Copy link
Contributor

z2s8 commented Oct 23, 2016

Setting $stdout.sync = true near the top of the file solved the problem for me.

@singram
Copy link
Author

singram commented Nov 2, 2017

Thanks! That did the trick for me as well ($stdout.sync = true). Would be useful to have in the documentation somewhere for others.

@rjpcasalino
Copy link

Just wanted to share my thanks as well! $stdout.sync = true worked for puts. I also learned about stdout flush today. Cheers!

mmrwoods added a commit to mmrwoods/docker-for-rails-devs that referenced this issue Feb 10, 2020
Set `$stdout.sync = true` in config/boot.rb, because Ruby buffers stdout
by default, and this doesn't play well with Docker Compose (data written
to stdout, e.g. via puts, may not be displayed on terminal).

See: sinatra/sinatra#1118
@jkowens jkowens closed this as completed Mar 19, 2020
nigel-lowry pushed a commit to DFE-Digital/get-help-with-tech that referenced this issue Apr 18, 2021
nigel-lowry pushed a commit to DFE-Digital/get-help-with-tech that referenced this issue May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants