New Instance Automatically Restarted and Lost All Contents

Hi!

So MySQL8 isn’t going to run on a low-ram environment - it OOM’s during it’s initialization phase (first run of MySQL). I’m not sure if it would also throw OOM errors during normal operation (haven’t gotten that far!)

However one thing I want to experiment with (and you can as well!) is setting up swap in the VM.

This would best be done in the ENTRYPOINT script.

It looks like you can add *.sh scripts to /docker-entrypoint-initdb.d and those will run automatically. However:

  1. Those run after other initialization, so I’m not sure we’d even reach these scripts for mysql 8 with 256m ram
  2. Those only run on the first-run, when adding to the mysql data directory. Subsequent restarts (deploys) would not run that script, so SWAP wouldn’t always get configured.

This means we need to setup a custom ENTRYPOINT script that adds some swap, and THEN runs the MySQL default entrypoint stuff (being sure to pass it any commands/flags, etc).

Doing this means we’d need our own Dockerfile that uses mysql8 as the base image.

The custom entrypoint could setup swap and then call the MySQL entrypoint (/usr/local/bin/docker-entrypoint.sh)

Haven’t tested this, but the custom entrypoint script could look something like this:

#!/bin/bash


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

`/usr/local/bin/docker-entrypoint.sh "$@"

Random reference:

Swap reference (we do it in the Rails launcher): flyctl/fly.rake at master · superfly/flyctl · GitHub

Mysql 8 entrypoint: mysql/docker-entrypoint.sh at master · docker-library/mysql · GitHub

1 Like