TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rails on Docker

329 pointsby mikecarltonover 2 years ago

27 comments

jchwover 2 years ago
&gt; Everything after that removes the manifest files and any temporary files downloaded during this command. It&#x27;s necessary to remove all these files in this command to keep the size of the Docker image to a minimum. Smaller Dockerfiles mean faster deployments.<p>It isn&#x27;t explicitly explained, but the reason why it must be in this command and not separated out is because each command in a dockerfile creates a new &quot;layer&quot;. Removing the files in another command will work, but it does nothing to decrease the overall image size: as far as whatever filesystem driver you&#x27;re using is concerned, deleting files from earlier layers is just masking them, whereas deleting them before creating the layer prevents them from ever actually being stored.
评论 #34535868 未加载
评论 #34534383 未加载
评论 #34535347 未加载
评论 #34536784 未加载
评论 #34535977 未加载
评论 #34537477 未加载
评论 #34534962 未加载
评论 #34534461 未加载
评论 #34537657 未加载
评论 #34539331 未加载
评论 #34542306 未加载
评论 #34536062 未加载
评论 #34534436 未加载
brundolfover 2 years ago
I used to think I hated Docker, but I think what I actually hate is using Docker locally (building&#x2F;rebuilding&#x2F;cache-busting images, spinning containers up and down, the extra memory usage on macOS, etc etc). I don&#x27;t need all that for development, I just want to run my dang code<p>But I&#x27;ve been really enjoying it as a way of just telling a PaaS &quot;hey here&#x27;s the compiler&#x2F;runtime my code needs to run&quot;, and then mostly not having to worry about it from there. It means these services don&#x27;t have to have a single list of blessed languages, while pretty much keeping the same PaaS user experience, which is great
评论 #34535284 未加载
评论 #34535035 未加载
评论 #34538706 未加载
评论 #34534495 未加载
评论 #34534423 未加载
评论 #34536191 未加载
评论 #34535010 未加载
评论 #34566174 未加载
评论 #34547423 未加载
nickjjover 2 years ago
If anyone is looking for a complete guide I put together this last month: <a href="https:&#x2F;&#x2F;nickjanetakis.com&#x2F;blog&#x2F;a-guide-for-running-rails-in-docker" rel="nofollow">https:&#x2F;&#x2F;nickjanetakis.com&#x2F;blog&#x2F;a-guide-for-running-rails-in-...</a><p>It includes running Rails and also Sidekiq, Postgres, Redis, Action Cable and ties in esbuild and Tailwind too. It&#x27;s all set up to use Hotwire as well. It&#x27;s managed by Docker Compose. The post also includes a ~1h hour ad-free YouTube video. The example app is open source at <a href="https:&#x2F;&#x2F;github.com&#x2F;nickjj&#x2F;docker-rails-example">https:&#x2F;&#x2F;github.com&#x2F;nickjj&#x2F;docker-rails-example</a> and it&#x27;s optimized for both development and production. No strings attached. The example app has been maintained and deployed a bunch over the years.
alberthover 2 years ago
Am I the only person who struggles to deploy Rails apps.<p>It&#x27;s a super productive framework to develop in, but deploying an actuals Rails apps - after nearly 20 years of existance, still seems way more difficult than it should be.<p>Maybe it&#x27;s just me.
评论 #34535118 未加载
评论 #34536101 未加载
评论 #34535196 未加载
评论 #34536447 未加载
评论 #34538702 未加载
评论 #34546758 未加载
评论 #34537123 未加载
评论 #34543694 未加载
评论 #34535643 未加载
评论 #34556966 未加载
评论 #34535001 未加载
评论 #34537926 未加载
评论 #34534944 未加载
评论 #34534923 未加载
评论 #34535138 未加载
sdwolfzover 2 years ago
I have my own local development Rails setup and template files that could be dropped in any project with minimal changes (mostly around configuring the db connection)<p>- <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;sdwolfz&#x2F;docker-projects&#x2F;-&#x2F;tree&#x2F;master&#x2F;rails" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;sdwolfz&#x2F;docker-projects&#x2F;-&#x2F;tree&#x2F;master&#x2F;rai...</a><p>Haven&#x27;t spent the time to document it. But the general idea is to have a `make` target that orchestrates everything so `docker-compose` can just spin things up.<p>I&#x27;ve used this sort of thing for multiple types of projects, not just Rails, it can work with any framework granted you have the right docker images.<p>For deployment I have something similar, builds upon the same concepts (with ansible instead of make, and focused on multi-server deploys, terraform for setting up the cloud resources), but not open sourced yet.<p>Maybe I&#x27;ll get to document it and post my own &quot;Show HN&quot; with this soon.
wefarrellover 2 years ago
I do miss the pre-docker days of using capistrano to deploy rails projects. Most deploys would take less than two minutes in the CI server and most of that was tests. The deploys were hot and requests that happened during the deploy weren&#x27;t interrupted. Now with Docker I&#x27;m seeing most deploys take around ten minutes.<p>The downside of capistrano was that you&#x27;d be responsible for patching dependencies outside of the Gemfile and there would be occasional inconsistencies between environments.
评论 #34539479 未加载
评论 #34535957 未加载
评论 #34536297 未加载
cvccvroomvroomover 2 years ago
Thanks but I already have my own containers and infrastructure for dev and prod Rails.<p>It&#x27;s fine for people who are just starting out or want a repeatable environment.<p>Also, if you want stability and fewer headaches long-term:<p>- use a RHEL-derived kernel and customize the userland (container or host) quay.io has a good cent 9 stream. Ubuntu isn&#x27;t used at significant scale for multiple reasons, and migrating over later is a pain.<p>- consider podman over docker<p>- use packaging (nix, habitat, or rpms) rather than make install (and use site-wide sccache)<p>- container management (k8s or nomad)<p>- configuration management (chef) because you don&#x27;t always have the luxury of 12factor ephemeral instances based on dockerfiles and need to make changes immediately without throwing away a database cluster or zookeeper ensemble<p>- Shard configuration and app changes, with a rollback capability<p>- Have CI&#x2F;CD for infrastructure that runs before landing<p>- Monitoring and alerting<p>- Don&#x27;t commit directly to production except for emergencies. Require a code review signoff by another engineer. And be able to back out changes.<p>- Have good, tested backups that aren&#x27;t replication<p>- Don&#x27;t sweat the small stuff, but get the big stuff right that doesn&#x27;t compound tech debt
agtorreover 2 years ago
This is really cool. Is the Rails server production ready? I was always under the impression you had to run it with Uvicorn or similar, although I haven&#x27;t been following Rails development recently.
评论 #34534512 未加载
评论 #34535523 未加载
jupp0rover 2 years ago
Will it be called &quot;Ruby on Whales&quot;? Joke aside, it&#x27;s trivial to write your own Dockerfile and this still is what nontrivial apps will do, due to customization.
评论 #34544256 未加载
rcarmoover 2 years ago
&gt; RAILS_SERVE_STATIC_FILES - This instructs Rails to not serve static files.<p>...but... it&#x27;s set to True....
评论 #34535165 未加载
评论 #34535084 未加载
dieselgateover 2 years ago
I&#x27;ve found the &quot;Docker for Rails Developers&quot; book by Rob Isenberg [1] to be a great resource for getting started using Rails and Docker. It&#x27;s only a couple years out of date at this point but should still be highly relevant for anyone trying to get started. The only issue I&#x27;ve had with Rails and Docker is serving the container on a 1gb d.o. droplet - the node-sass gem is usually a sticking point for a lot of people and believe the 1gb droplet to be just too small to host a dockerized rails app. But the benefits of using docker for Development is still overwhelmingly worth the effort of containerizing things.<p>It&#x27;s super cool rails 7.1 is including the Dockerfile by default - not that rails apps need more boilerplate though..<p>[1]: <a href="https:&#x2F;&#x2F;pragprog.com&#x2F;titles&#x2F;ridocker&#x2F;docker-for-rails-developers&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pragprog.com&#x2F;titles&#x2F;ridocker&#x2F;docker-for-rails-develo...</a>
deweyover 2 years ago
This is long overdue. Rails got very nice updates in the past years to make it easier to handle JS and other assets.<p>Deploying it was still always a hassle and involved searching for existing Dockerfiles and blog posts to cobble together a working one. At the beginning I always thought I&#x27;m doing something wrong as it&#x27;s supposed to be easy and do everything nicely out of the box.<p>And dhh apparently agrees (Now at least: <a href="https:&#x2F;&#x2F;dhh.dk&#x2F;posts&#x2F;30-myth-1-rails-is-hard-to-deploy" rel="nofollow">https:&#x2F;&#x2F;dhh.dk&#x2F;posts&#x2F;30-myth-1-rails-is-hard-to-deploy</a>) as there&#x27;s now a default Dockerfile and also this project he&#x27;s working on, this will make things a lot nicer and more polished: <a href="https:&#x2F;&#x2F;github.com&#x2F;rails&#x2F;mrsk">https:&#x2F;&#x2F;github.com&#x2F;rails&#x2F;mrsk</a>
评论 #34536340 未加载
bradgesslerover 2 years ago
I have a proposal out for making the deployment story even easier by providing RubyGems a way to describe the packages they depend on to operate properly at <a href="https:&#x2F;&#x2F;community.fly.io&#x2F;t&#x2F;proposal-declare-docker-images-dependencies-via-the-ruby-slim-docker-packages-key-in-gemspec-metadata&#x2F;9979&#x2F;11">https:&#x2F;&#x2F;community.fly.io&#x2F;t&#x2F;proposal-declare-docker-images-de...</a><p>The idea is I could run a command like `bundle packages --manager=apt` and get a list of all the packages `apt` should install for the gems in my bundle.<p>Since I know almost nothing about the technicalities and community norms of package management in Linux, macOS, and Windows, I&#x27;m hoping to find people who do and care about making the Ruby deployment story even better to give feedback on the proposal.
评论 #34536352 未加载
ginzunzaover 2 years ago
This is a manual using that image with Redis and Postgres: <a href="https:&#x2F;&#x2F;medium.com&#x2F;@gustavoinzunza&#x2F;rails-redis-pg-with-docker-compose-in-2023-64ebb6d25de1" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;@gustavoinzunza&#x2F;rails-redis-pg-with-docke...</a>
revskillover 2 years ago
This is a really good news. And to be fun, the easiest way to become mainstream, is to have a guide on how to deploy a Rails application in 1 click, for any cloud hosting service.
laneystroupover 2 years ago
I still use Capistrano. In fact, I like Capistrano so much that I have full Load Balancing, Auto-Scaling, and End-to-End encryption enabled for my projects on AWS via the elbas gem.<p>My primary use case for this is PCI Compliance. While PCI DSS and&#x2F;or HIPAA do not specifically rule out Docker, the principle of isolation leans heavily twoard the principle that web hosts must be running on a private virtual machine.<p>This rules out almost all docker based-PaaS (including Fly.io, Render.com, AWS App Runner, and Digital Ocean), as these run your containers on general Docker hosts. In fact, the only PaaS provider that I can find advertising PCI compliance is Heroku, which now charges +$1800&#x2F;month plus for Heroku Private to achieve it.<p>I would love to share my configuration with anyone that needs it.
评论 #34539749 未加载
评论 #34540197 未加载
评论 #34539810 未加载
评论 #34540026 未加载
评论 #34539685 未加载
e12eover 2 years ago
For some more (too many?) in-depth tricks for rails and docker, see also:<p>&quot;Ruby on Whales: Dockerizing Ruby and Rails development&quot;<p><a href="https:&#x2F;&#x2F;evilmartians.com&#x2F;chronicles&#x2F;ruby-on-whales-docker-for-ruby-rails-development" rel="nofollow">https:&#x2F;&#x2F;evilmartians.com&#x2F;chronicles&#x2F;ruby-on-whales-docker-fo...</a><p>Previously posted to hn - but without any comments.
throwaway23942over 2 years ago
I use FROM scratch. The app itself is built with a binary packer that is copied in.<p>Still, I&#x27;d much rather use Nix&#x2F;Guix over Dockerfile.
023984398over 2 years ago
This is awesome and I&#x27;m glad Rails is adding something official here. Unfortunately if you want to use the Dockerfile in development with docker-compose you will need to make some changes&#x2F;additions. Most notably: only precompile assets if deploying, not during development
thrownaway561over 2 years ago
Though this is a great step... you still have to edit the Dockerfile if you are using Postgres and Redis.
marcopicentiniover 2 years ago
Deploying with Cloud66 is a lot easier. Just git push.<p>I can chose my hosting provider and switch each other.
iamflimflam1over 2 years ago
What kills rails for me at the moment is the time it takes to start up. I&#x27;d love to be able to use on top of things like cloud run where resources ramp down to zero when there are no requests, but the startup time makes this very difficult.
评论 #34539422 未加载
评论 #34536345 未加载
评论 #34535626 未加载
评论 #34542764 未加载
bploetzover 2 years ago
It&#x27;s been a while since I&#x27;ve done any Ruby&#x2F;Rails development, but just curious why they chose to use a Debian&#x2F;Ubuntu based image in the default Dockerfile instead of an Alpine based image?
评论 #34536388 未加载
评论 #34542787 未加载
评论 #34536163 未加载
bencedover 2 years ago
As someone who doesn’t know rails at all, what’s the innovation here? Surely Rails has had Dockerfiles written for it before?
garfieldnateover 2 years ago
How on earth did Rails not have an official Dockerfile until now? Have people been deploying like it&#x27;s 2010?
hit8runover 2 years ago
I use dokku. Works really well.
评论 #34537805 未加载
quest88over 2 years ago
But how does this work when talking to dev databases on my machine?
评论 #34542801 未加载
评论 #34540176 未加载