Member-only story
Rails + Docker Done Right: Lessons From 3 Failed Deployments
How I learned to stop worrying and love containerization (after breaking production three times)
We once broke production three times trying to Dockerize our Rails app. Three. Times.
Each failure was spectacular in its own way. The first one took down our entire staging environment for six hours. The second one mysteriously worked locally but refused to boot in production. The third? Let’s just say our CI/CD pipeline became sentient and decided to spite me personally.
But here’s the thing — each failure taught me something crucial about how Rails and Docker actually work together. And after finally getting it right, our deployment time dropped from 23 minutes to 4 minutes, our builds became 60% smaller, and I stopped waking up at 3 AM to fix container issues.
So let me save you the pain. Here’s what I learned.
Failure #1: The “It Works On My Machine” Disaster
My first attempt was embarrassingly naive. I basically threw together a Dockerfile based on a tutorial from 2019 and called it a day:
FROM ruby:3.2
WORKDIR /app
COPY . .
RUN bundle install
CMD ["rails", "server"]