Deploying Strapi on Fly.io

I am trying to get a Strapi application running on Fly.io. There is a PR in the Strapi repo which gives deployment instructions, so I followed them.

Bad news: they don’t work. I’ve put a comment on the PR to alert OP to this, but @lubien suggested I should ask the question here too, where more Fly.io folks would see it. Here’s what Fly.io looks like:

The logs say that Strapi actually starts, but then it dies again:

2022-08-14T17:02:19.541 runner[2fe10c23] lhr [info] Starting instance
2022-08-14T17:02:20.004 runner[2fe10c23] lhr [info] Configuring virtual machine
2022-08-14T17:02:20.010 runner[2fe10c23] lhr [info] Pulling container image
2022-08-14T17:02:31.785 runner[2fe10c23] lhr [info] Unpacking image
2022-08-14T17:02:48.227 runner[2fe10c23] lhr [info] Preparing kernel init
2022-08-14T17:02:48.593 runner[2fe10c23] lhr [info] Configuring firecracker
2022-08-14T17:02:48.768 runner[2fe10c23] lhr [info] Starting virtual machine
2022-08-14T17:02:48.993 app[2fe10c23] lhr [info] Starting init (commit: c86b3dc)...
2022-08-14T17:02:49.020 app[2fe10c23] lhr [info] Preparing to run: `/cnb/process/web` as heroku
2022-08-14T17:02:49.050 app[2fe10c23] lhr [info] 2022/08/14 17:02:49 listening on [fdaa:0:81f5:a7b:be65:2fe1:c23:2]:22 (DNS: [fdaa::3]:53)
2022-08-14T17:02:49.601 app[2fe10c23] lhr [info] yarn run v1.22.19
2022-08-14T17:02:49.629 app[2fe10c23] lhr [info] $ strapi start
2022-08-14T17:02:53.380 app[2fe10c23] lhr [info] [2022-08-14 17:02:53.377] info: The Users & Permissions plugin automatically generated a jwt secret and stored it in .env under the name JWT_SECRET.
2022-08-14T17:02:53.637 app[2fe10c23] lhr [info] Project information
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] ┌────────────────────┬──────────────────────────────────────────────────┐
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] │ Time │ Sun Aug 14 2022 17:02:53 GMT+0000 (Coordinated … │
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] │ Launched in │ 1640 ms │
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] │ Environment │ development │
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] │ Process PID │ 536 │
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] │ Version │ 4.3.4 (node v15.14.0) │
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] │ Edition │ Community │
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] └────────────────────┴──────────────────────────────────────────────────┘
2022-08-14T17:02:53.654 app[2fe10c23] lhr [info] Actions available
2022-08-14T17:02:53.655 app[2fe10c23] lhr [info] One more thing...
2022-08-14T17:02:53.655 app[2fe10c23] lhr [info] Create your first administrator 💻 by going to the administration panel at:
2022-08-14T17:02:53.656 app[2fe10c23] lhr [info] ┌─────────────────────────────┐
2022-08-14T17:02:53.656 app[2fe10c23] lhr [info] │ http://localhost:8080/admin │
2022-08-14T17:02:53.656 app[2fe10c23] lhr [info] └─────────────────────────────┘
2022-08-14T17:07:33.942 runner[2fe10c23] lhr [info] Shutting down virtual machine
2022-08-14T17:07:34.027 app[2fe10c23] lhr [info] Sending signal SIGINT to main child process w/ PID 516
2022-08-14T17:07:35.031 app[2fe10c23] lhr [info] Main child exited with signal (with signal 'SIGINT', core dumped? false)
2022-08-14T17:07:35.032 app[2fe10c23] lhr [info] Starting clean up. 

I’m using the .env which came with yarn create, which uses the Strapi standard port 1337. Here is the fly.toml created by fly launch, modified as directed in the proposed Strapi guide doc:

# fly.toml file generated for my-app on 2022-08-14T16:21:23+01:00

app = "my-app"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  builder = "heroku/buildpacks:20"

[env]
  PORT = "8080"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 1337
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

The Dockerfile does indeed EXPORT 1337. I presume I should be able to reach the service on https://my-app.fly.dev:8080, right? That URL just hangs and then times out.

Any suggestions would be much appreciated.

Actually, it’s a mapping of pots. Your app listens to port 8080 and the setting internal_port should be 8080 so it maps it to port 80 (meaning http://your-app.fly.dev) and port 443 (meaning httpS://your-app.fly.dev).

Another interesting thing is that you have a dockerfile but you fly.toml has a builder. Feel free to remove this:

[build]
  builder = "heroku/buildpacks:20"
1 Like

Thank you for the quick reply! Good point about the heroku builder, I’ve removed that.

And I now understand what’s going on. You’re right, it’s a port issue. In my local .env, the PORT environment variable is set to Strapi’s usual 1337. But of course, the .env isn’t committed. In the fly.toml, I’m setting the same env var to 8080. But the Dockerfile is set to EXPORT 1337, and so Strapi is listening on a port that Docker isn’t exporting.

Once I changed PORT to 1337 too, it worked! Thanks very much for your timely help.

2 Likes