Fail to run MySQL app from Dockerfile

Hi, I’m trying to deploy an app using the mysql image but I always get this error message:

$ flyctl launch
#...
#...
Image: registry.fly.io/test-db:deployment-1656895318
Image size: 462 MB
==> Creating release
Release v11 created

You can detach the terminal anytime without stopping the deployment
Monitoring Deployment

v9 failed - Failed due to unhealthy allocations - no stable job version to auto revert to
v9 failed - Failed due to unhealthy allocations - no stable job version to auto revert to
***v9 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v10

Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

The intention is to connect a Ruby on Rails app with this service, so I would like it to be a private connection.

what am i doing wrong?

My Dockerfile

FROM mysql:5.7.38

RUN chown -R mysql:root /var/lib/mysql/

ENV MYSQL_ALLOW_EMPTY_PASSWORD true

ARG MYSQL_DATABASE=revistajus_production
ARG MYSQL_USER=root
ARG MYSQL_PASSWORD=root
ARG MYSQL_ROOT_PASSWORD=root

ENV MYSQL_DATABASE=${MYSQL_DATABASE}
ENV MYSQL_USER=${MYSQL_USER}
ENV MYSQL_PASSWORD=${MYSQL_PASSWORD}
ENV MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}

EXPOSE 3306

CMD ["mysqld"]

Configs

# fly.toml file generated for test-db on 2022-07-03T20:31:37-03:00

app = "test-db"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]
  port = 3306

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[mounts]
  source="test_data"
  destination="/data"

[[services]]
  http_checks = []
  internal_port = 3306
  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"

Try removing everything under [[services]]. “Failed due to unhealthy allocations” could either mean that the process is crashing, or that health checks are failing.

If you run fly status --all you can get a list of the VMs it has tried to launch. Then run fly vm status <id> and it’ll give you more information about why it exited.

1 Like

In this case you might want to remove [[services]] entirely because this section teaches Fly we need to expose your app :wink: Remove this:

[[services]]
  http_checks = []
  internal_port = 3306
  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"

This would make your MySQL available at your-app-name.internal:3306 (assuming the port is indeed 3306).


As for what happened (just in case you’re curious):

v9 failed - Failed due to unhealthy allocations - no stable job version to auto revert to

“Failed due to unhealthy allocations” means that health checks didn’t pass, which would lead us to think your MySQL might have not be attached to HOST 0.0.0.0 or PORT 3306 (we’d need to see logs to verify that). The “no stable job version to auto revert to” means you didn’t deploy a successful release before so we can’t find a good rollback candidate.

1 Like

It worked with @kurt tip! I removed the [[services]] session

That was another question:

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: ******
  password: ******
  port: 3306
  host: my-app.internal

All done! Thanks! :relaxed:

2 Likes