When you build the environment with docker and do docker-compose up
to start the server
I get the error Mysql2 :: Error :: ConnectionError: Unknown MySQL server host'db' (-2)
.
If you check the error log in the terminal It seems that the DB has shut down for some reason.
Since it is privilege tables
, is it a user's table created by sudo?
Why do I get an error with this content in docker?
I wondered variously, but for the time being, I decided to delete all the volumes once.
① Check the volume ID
$ docker volume ls
DRIVER VOLUME NAME
local b1d0c8467782387a61c446e1ea2aedaa745d6f120c4c6423bdc37e9005a7bd34
(2) Delete volume with the rm command using the VOLUME NAME
checked above.
$ docker volume rm [VOLUME NAME]
#Example ↓
$ docker volume rm b1d0c8467782387a61c446e1ea2aedaa745d6f120c4c6423bdc37e9005a7bd34
③ Restart the container & server based on docker-compose.yml
$ docker-compose up --build
$ docker-compose run web rails db:create
$ docker-compose run web rails db:migrate
④ Access localhost: 3000 → ** Start without error **
Since the place where the table information of mysql is saved is volume, when the container was deleted, the volume container was not completely deleted, and the previous mysql information was left halfway
, so it seems that the authority was insufficient. is.
Before this, I made a container many times, deleted it, and repeated trial and error, so it is probably the wreckage at that time ...
If db does not start with docker-compose up, try deleting volume
Recommended Posts