How to swap properly? "Out of memory: Killed process (node)" error on deploy

I’ve got two postgres apps, staging and prod. The prod one is pretty beefy, but the staging instance is the skimpiest one, because it really doesn’t get any traffic.

But it keeps running out of memory when I deploy, because I think a Prisma migration task. It’s run via the deploy command:

  release_command = "npx prisma migrate deploy"

In the docs it says:

This command runs in a temporary VM - using the successfully built release - before that release is deployed.

So, am I running out of memory on this temporary VM or in my main machine?

One solution

I used a script to set some swap and run the needed scripts:

fallocate -l 512M /swapfile
chmod 0600 /swapfile
mkswap /swapfile
echo 10 > /proc/sys/vm/swappiness
swapon /swapfile

npx prisma migrate deploy

# Turn off swap
swapoff /swapfile
rm /swapfile

npm run start


  cmd = ""
  entrypoint = "sh"


COPY --from=build /myapp/ /myapp/
COPY --from=build /myapp/prisma /myapp/prisma
ADD . .

Is this the “correct” way to do it? I mean it works so I’m happy.


Yep, that sounds like it’s the temporary VM failing.

That’s also the way we would setup swap as well - in the ENTRYPOINT script (err, well in your case, you set it as CMD, but if it works, that’s cool).

The key point is that you can’t setup swap in the Dockerfile when creating the image that gets deployed, but instead need to do that when the VM is booted, and hence the ENTRYPOINT or CMD is the place to do it :+1:

One note:

Your Dockerfile defines ENTRYPOINT as but then fly.toml is over-riding that by setting sh as ENTRYPOINT and as the CMD.

You could instead:

  1. Keep as entrypoint as defined in the Dockerfile, perhaps also set the full path (/myapp/ instead of relative path ./
  2. Ensure is executable (chmod +x /myapp/
  3. Ensure will use the correct shell by prepending #! /bin/sh to the top of the file
  4. Remove the [experimental] section from fly.toml so the settings in Dockerfile are used

That’s optional but is just a bit cleaner.

1 Like

Thanks for the tips!

1 Like

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