I'm trying to docker
ize 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:
Machine reboot
Update Docker
Map host port 443 to container port 3000
$RAILS_ENV
both as development and productionVariations of rails command in docker file:
CMD [ "bundle", "exec", "rails", "s", "-b", "0.0.0.0" ]
CMD [ "rails", "s", "-b", "127.0.0.1" ]
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.