The generated Dockerfile
How Hatchbox builds a Rails app that has no Dockerfile, and when to commit your own
Updated
On a Dockerfile cluster, a Rails app doesn't need a Dockerfile in its repository. When the commit being deployed has none at the build path, Hatchbox generates the one rails new writes, filled in from your repository.
What it contains
- A multi-stage build on the official
rubyimage, for the version in.ruby-versionorGemfile.lock. - The system packages the gems in
Gemfile.lockneed: the PostgreSQL, MySQL or SQLite client, libvips for Active Storage, ImageMagick for Paperclip and RMagick, and so on. - Node in the build stage when the app compiles JavaScript (a bundling gem, Webpacker, Vite, or Sprockets with
execjs), with the package manager the lock file names (npm, Yarn, pnpm or Bun) and the Node version from.node-versionorpackage.json'sengines, otherwise the current LTS. - bootsnap and assets precompiled at build time, with
RAILS_MASTER_KEYmounted as a build secret. - The
BUNDLE_<HOST>credentials for each private git gem inGemfile.lock, mounted as build secrets, so aBUNDLE_GITHUB__COMenv var on the app is all a private gem needs. - Thruster on port 80 when the app has the gem, otherwise Puma on port 3000, running as a non-root user with jemalloc.
It follows your app
The file is generated again on every deploy, from the commit and Hatchbox's template, so a change to your gems or versions is picked up, and so are improvements to the template. The deploy log says what it was built for and shows what changed since the last deploy's. The new-app form tells you whether a branch will get a generated Dockerfile before you create the app.
Committing it yourself
Nothing is written to your repository. The generated file is under Dockerfile in the app's settings, where you can copy or download it, or open it prefilled in GitHub's or GitLab's new-file editor to commit it.
Once a Dockerfile is committed at the build path, Hatchbox builds that one as it is. That's also how you change it: commit it and edit it in your repository. There's no Dockerfile editor in Hatchbox.
When it can't be generated
A Dockerfile can't be generated when:
- the repository has no
Gemfile.lockat the root, - the app isn't Rails or has no
bin/rails, - no Ruby version is named, or
- a gem needs Chromium in the running image (
grover,ferrum_pdf,puppeteer-ruby).
Those apps need a Dockerfile in the repository, and the new-app form and the deploy say why. Apps on Ruby 2.x build too: their Debian release is past its end of life, so the generated file takes packages from the Debian archive.
Bringing your own Dockerfile
Hatchbox builds the final stage of your Dockerfile, so put your production stage last. A development stage after it (with Chromium for system tests, say) ends up in production. Make sure the build precompiles your assets, since the image has to contain them.