Using Custom Dockerfiles with Multi-container Machines

I have a somewhat complex app that is running both a Rails server and a Node.js server with nginx proxying requests to them depending on the route (I’m attempting to slowly migrate a Rails app to Node.js). I’m brand new to Fly.io and I was trying to figure out if I could deploy to multiple machines using a different Dockerfile for each. The Multi-container Machines page seems to describe what I’m trying to do, but I can’t figure out how to use Dockerfiles stored in the repository instead of image names/URLs.

Is this possible? Or is there a better way to accomplish what I’m trying to do? I also found this article, but I’d prefer to use a separate Dockerfile for the Rails/Node.js servers if possible.

Hey there,

This is actually a great question and use case. I’d love to see if this works! Could you try the following and let me know if it helps?

Because there’s no native way to deploy multiple Dockerfiles in one fly deploy. Instead, you’ll want to:

  1. Build each Dockerfile separately and push them to Fly’s registry:
docker build -t registry.fly.io/my-app:rails -f rails/Dockerfile .
docker push registry.fly.io/my-app:rails

docker build -t registry.fly.io/my-app:node -f node/Dockerfile .
docker push registry.fly.io/my-app:node
  1. Use something like flyctl machine create (or the Machines API) to spin up separate machines using those images. Each machine can run a different service (Rails or Node), and you can configure them independently.

  2. If you need routing between them, you can run a third machine with NGINX that proxies requests to the others based on the path.

This in theory should get you to your resolution, but I’m curious to know if you run into any pitfalls/issues. However, the Multi-container machines guide should get you to the resolution you are looking for as well. My suggestion was more of an alternative, to the guide. I wasn’t entirely sure what resolution “direction” you were looking for.

Ok, if I can’t have multiple images built as part of deploying, then I might go the single image route to keep deployment as simple as possible. Thanks for the help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.