Hey team, been playing around a bit with Fly recently and writing a blog post to explain how to get an Express app spun up.
I’m a big container noob so mostly just following along with docs, running commands and seeing what happens. I know there’s a troubleshooting guide but a lot of it’s over my head, so my apologies for not RTFM and I’m sure I’m making a silly mistake somewhere along the way.
I’ve got this current project that’s erroring out:
index.js
const express = require("express")
const app = express()
const port = process.env.PORT || 3000
app.get(
"/", (req, res) => {
greeting = "<h1>ajcwebdev-fly</h1>"
res.send(greeting)
}
)
app.listen(
port,
() => console.log(`Hello from port ${port}!`)
)
Run server
node index.js
Hello from port 3000!
Dockerfile
FROM node:14-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . ./
EXPOSE 8080
CMD [ "node", "index.js" ]
.dockerignore
node_modules
Dockerfile
.dockerignore
.git
.gitignore
npm-debug.log
Launch app on Fly
flyctl launch --name ajcwebdev-fly --region sjc
Creating app in /Users/ajcwebdev/ajcwebdev-fly
Scanning source code
Detected NodeJS app
Using the following build configuration:
Builder: heroku/buildpacks:20
Buildpacks:
Automatically selected personal organization: Anthony Campolo
Created app ajcwebdev-fly in organization personal
Wrote config file fly.toml
Your app is ready. Deploy with `flyctl deploy`
fly.toml
app = "ajcwebdev-fly"
kill_signal = "SIGINT"
kill_timeout = 5
[env]
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 6
timeout = "2s"
Deploy application with flyctl deploy
flyctl deploy
Deploying ajcwebdev-fly
==> Validating app configuration
--> Validating app configuration done
Services
TCP 80/443 ⇢ 8080
==> Creating build context
--> Creating build context done
==> Building image with Docker
Sending build context to Docker daemon 37.38kB
[+] Building 14.3s (10/10) FINISHED
=> [internal] load remote build context 0.0s
=> copy /context / 0.1s
=> [internal] load metadata for docker.io/library/node:14-alpine 1.8s
=> [1/5] FROM docker.io/library/node:14-alpine@sha256:fb6cb918cc72869bd625940f42a7d8ae035c4e786d08187b94e8b91c6 6.3s
=> => resolve docker.io/library/node:14-alpine@sha256:fb6cb918cc72869bd625940f42a7d8ae035c4e786d08187b94e8b91c6 0.0s
=> => sha256:59857143b3784bf4afb6f93a8082180e88faa75a8efee07147589552843e5433 36.21MB / 36.21MB 5.0s
=> => sha256:9f27d30bcf3a07255d5080e92a199cd8cf154bb91526f9519b2355687cd15eab 2.24MB / 2.24MB 1.6s
=> => sha256:fb6cb918cc72869bd625940f42a7d8ae035c4e786d08187b94e8b91c6a534dfd 1.43kB / 1.43kB 0.0s
=> => sha256:5c33bc6f021453ae2e393e6e20650a4df0a4737b1882d389f17069dc1933fdc5 1.16kB / 1.16kB 0.0s
=> => sha256:f5f48375fc5d0df18a96d337019e7dc4e99efd4d98f9e8ab53af74c56de91de3 6.53kB / 6.53kB 0.0s
=> => sha256:ddad3d7c1e96adf9153f8921a7c9790f880a390163df453be1566e9ef0d546e0 2.82MB / 2.82MB 0.6s
=> => extracting sha256:ddad3d7c1e96adf9153f8921a7c9790f880a390163df453be1566e9ef0d546e0 0.1s
=> => sha256:be8cf85a075db5d053c8652e924886e96d26ed77c1cce39ad75e22ae41de5236 281B / 281B 0.9s
=> => extracting sha256:59857143b3784bf4afb6f93a8082180e88faa75a8efee07147589552843e5433 1.0s
=> => extracting sha256:9f27d30bcf3a07255d5080e92a199cd8cf154bb91526f9519b2355687cd15eab 0.1s
=> => extracting sha256:be8cf85a075db5d053c8652e924886e96d26ed77c1cce39ad75e22ae41de5236 0.0s
=> [2/5] WORKDIR /usr/src/app 0.1s
=> CACHED copy /context / 0.0s
=> [3/5] COPY package*.json ./ 0.0s
=> [4/5] RUN npm i 5.9s
=> [5/5] COPY . ./ 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:2e86fa4eedeb4e7b4a5ece2b5167e1c7a6e810bc1c8c0a69463ca57bc8ea2698 0.0s
=> => naming to registry.fly.io/ajcwebdev-fly:deployment-1627521878 0.0s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/ajcwebdev-fly]
e503c0f3789e: Pushed
efbef288213d: Pushed
dea459947eea: Pushed
f74349670ae4: Pushed
87f6a206d8c2: Pushed
efe9f72a5423: Pushed
ffa572135c58: Pushed
9a5d14f9f550: Pushed
deployment-1627521878: digest: sha256:38dbfc7e0441f180702f1ebc763c621d85c39818c0e487f3ee99d4603ef42d9b size: 1992
--> Pushing image done
Image: registry.fly.io/ajcwebdev-fly:deployment-1627521878
Image size: 120 MB
==> Creating release
Release v0 created
You can detach the terminal anytime without stopping the deployment
Monitoring Deployment
1 desired, 1 placed, 0 healthy, 1 unhealthy [restarts: 2] [health checks: 1 total, 1 critical]
v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to
Failed Instances
==> Failure #1
Instance
ID = 808d096b
Version = 0
Region = sjc
Desired = run
Status = running
Health Checks = 1 total, 1 critical
Restarts = 2
Created = 4m7s ago
Recent Events
TIMESTAMP TYPE MESSAGE
2021-07-29T01:26:15Z Received Task received by client
2021-07-29T01:26:15Z Task Setup Building Task Directory
2021-07-29T01:26:19Z Started Task started by client
2021-07-29T01:27:36Z Restart Signaled healthcheck: check "66cf15a97e3a024dadbbfb595963ba3f" unhealthy
2021-07-29T01:27:39Z Terminated Exit Code: 130
2021-07-29T01:27:39Z Restarting Task restarting in 1.029876556s
2021-07-29T01:27:41Z Started Task started by client
2021-07-29T01:28:58Z Restart Signaled healthcheck: check "66cf15a97e3a024dadbbfb595963ba3f" unhealthy
2021-07-29T01:29:01Z Terminated Exit Code: 130
2021-07-29T01:29:01Z Restarting Task restarting in 1.125485629s
2021-07-29T01:29:03Z Started Task started by client
Recent Logs
2021-07-29T01:27:41Z [info] Configuring firecracker
2021-07-29T01:27:41Z [info] Starting virtual machine
2021-07-29T01:27:41Z [info] Starting init (commit: cc4f071)...
2021-07-29T01:27:41Z [info] Running: `docker-entrypoint.sh node index.js` as root
2021-07-29T01:27:41Z [info] 2021/07/29 01:27:41 listening on [fdaa:0:2f5b:a7b:ad1:808d:96b:2]:22 (DNS: [fdaa::3]:53)
2021-07-29T01:27:41Z [info] Hello from port 3000!
2021-07-29T01:27:49Z [warn] Health check status changed 'passing' => 'warning'
2021-07-29T01:27:58Z [error] Health check status changed 'warning' => 'critical'
2021-07-29T01:28:58Z [info] Shutting down virtual machine
2021-07-29T01:28:58Z [info] Sending signal SIGINT to main child process w/ PID 507
2021-07-29T01:28:59Z [info] Main child exited with signal (with signal 'SIGINT', core dumped? false)
2021-07-29T01:28:59Z [info] Starting clean up.
2021-07-29T01:29:02Z [info] Starting instance
2021-07-29T01:29:02Z [info] Configuring virtual machine
2021-07-29T01:29:02Z [info] Pulling container image
2021-07-29T01:29:03Z [info] Unpacking image
2021-07-29T01:29:03Z [info] Preparing kernel init
2021-07-29T01:29:03Z [info] Configuring firecracker
2021-07-29T01:29:03Z [info] Starting virtual machine
2021-07-29T01:29:03Z [info] Starting init (commit: cc4f071)...
2021-07-29T01:29:03Z [info] Running: `docker-entrypoint.sh node index.js` as root
2021-07-29T01:29:03Z [info] 2021/07/29 01:29:03 listening on [fdaa:0:2f5b:a7b:ad1:808d:96b:2]:22 (DNS: [fdaa::3]:53)
2021-07-29T01:29:04Z [info] Hello from port 3000!
2021-07-29T01:29:04Z [info] Health check status changed 'critical' => 'passing'
2021-07-29T01:29:08Z [warn] Health check status changed 'passing' => 'warning'
2021-07-29T01:29:17Z [error] Health check status changed 'warning' => 'critical'
2021-07-29T01:30:21Z [info] Shutting down virtual machine
2021-07-29T01:30:21Z [info] Sending signal SIGINT to main child process w/ PID 507
2021-07-29T01:30:22Z [info] Main child exited with signal (with signal 'SIGINT', core dumped? false)
2021-07-29T01:30:22Z [info] Starting clean up.
***v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1
Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
flyctl status
flyctl status
App
Name = ajcwebdev-fly
Owner = personal
Version = 0
Status = dead
Hostname = ajcwebdev-fly.fly.dev
Deployment Status
ID = 61205d95-4f62-0abe-5d0c-43680a47eb4f
Version = v0
Status = failed
Description = Failed due to unhealthy allocations - no stable job version to auto revert to
Instances = 1 desired, 1 placed, 0 healthy, 1 unhealthy
Instances
ID VERSION REGION DESIRED STATUS HEALTH CHECKS RESTARTS CREATED
flyctl open
flyctl open
Opening http://ajcwebdev-fly.fly.dev/