Home > Software engineering >  Dockerized Rails 7 Puma SSL fails with 'PR_END_OF_FILE_ERROR'
Dockerized Rails 7 Puma SSL fails with 'PR_END_OF_FILE_ERROR'

Time:11-09

I'm trying to dockerize a rails 7 app using the default puma server with ssl enabled using a self-signed cert. Launching the app natively works as expected.

When running as a container, I get a 'PR_END_OF_FILE_ERROR' error in Firefox. Testing with other browsers results in 'This site can'be reached. localhost unexepectedly closed the connection'.

docker run command: docker run --rm -it -p 3000:3000 my-app-image

Dockerfile CMD: CMD [ "rails", "s" ]

Troubleshooting steps:

  1. Machine reboot

  2. Update Docker

  3. Map host port 443 to container port 3000

  4. $RAILS_ENV both as development and production

  5. Variations of rails command in docker file:

    1. CMD [ "bundle", "exec", "rails", "s", "-b", "0.0.0.0" ]
    2. CMD [ "rails", "s", "-b", "127.0.0.1" ]
    3. CMD [ "rails", "s", "-u", "puma", "-b", "'ssl://127.0.0.1/?key=server.key&cert=server.crt&verify_mode=none'" ]

config/application.rb

...
# Enable SSL
config.force_ssl = true
...

config/puma.rb

...
environment ENV.fetch("RAILS_ENV") { "development" }

# SSL Configuration
localhost_key = 'server.key'
localhost_crt = 'server.crt'

ssl_bind 'localhost', 3000, {
  key: localhost_key,
  cert: localhost_crt,
  verify_mode: 'none'
}
...

Since it works when run natively, I think the issue lies with either docker or puma, but I'm not sure what it could be or how to troubleshoot further.

CodePudding user response:

The issue was binding the ssl port in the puma.rb config file to localhost, which isn't available outside of the running container.

Changing:

ssl_bind 'localhost', 3000, {

To:

ssl_bind '0.0.0.0', 3000, {

resolved the issue.

  • Related