I'm using exactly the same command (CMD) in my test deployment and it works, this makes me think that maybe you're interpreting the unhealthy state as the health check command not working, but there are a number of other reasons for that state.
For example, during my tests it wasn't able to start because I was using EFS to provide permanent storage and every time I was updating the task, the files were not deleted, so the container was failing because it was Unable to lock ./ibdata1.
There's apparently a second issue anyway, because CMD and CMD-SHELL (which are part of the docker syntax and unrelated the OS), requires a different syntax: CMD need a list, while CMD-SHELL allows a single string as the second item of the array.
Basically, if you try this in compose, it works:
["CMD","mysqladmin","ping","-h","localhost"]
this does not:
["CMD-SHELL","mysqladmin","ping","-h","localhost"]
and it should be instead:
["CMD-SHELL","mysqladmin ping -h localhost"]
So to answer the question, make sure to create a log group on Cloudwatch and set the "logConfiguration" into the container definition and check the logs, more than likely there's something wrong into that container, and make sure to use the right syntax into the container definition, either this example
"healthCheck": {
"retries": 3,
"command": ["CMD","mysqladmin","ping","-h","localhost"],
"timeout": 5,
"interval": 5,
"startPeriod": null
},
or this one - provided a shell has been defined into the container
"healthCheck": {
"retries": 3,
"command": ["CMD-SHELL","mysqladmin ping -h localhost"],
"timeout": 5,
"interval": 5,
"startPeriod": null
},
Into your logs you should find a lot of record like
[Note] Access denied for user 'root'@'localhost' (using password: NO)
Which is the healthcheck running. It fails because we didn't set any password, but as the mysqladmin docs are stating:
The return status from mysqladmin is 0 if the server is running, 1 if it is not. This is 0 even in case of an error such as Access denied, because this means that the server is running but refused the connection, which is different from the server not running.