What I did when the DB did not start with docker-compose up

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 image.png 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.

solution

① 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 **

Cause

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 ...

Referenced articles

If db does not start with docker-compose up, try deleting volume

Recommended Posts

What I did when the DB did not start with docker-compose up
The story when the container does not start up with docker-compose up and an error occurs
When the server does not start with rails s
In WSL2, when I did `docker-compose up`, I got an error saying that the sh file was not found.
Container does not start with docker-compose
If the DB container does not start with Initializing database files
What I did when JSF couldn't display database information in the view
What I checked when I installed Docker Hub in a Windows 10 home environment but it did not start
What I did when I converted java to Kotlin
I can't do docker-compose up -d with docker
What to do when rails db: seed does not reflect in the database
[Grails] Error occurred running What to do when the Grails CLI does not start
What to do when is invalid because it does not start with a'-'
What is `docker-compose up`?
The procedure I did when I prepared the environment of gradle + Java with VS Code (Windows 10)
[Summary] What I noticed and did when I was told that the Oracle JDK was paid
Start k3s with docker-compose
The story that did not disappear when I tried to delete mysql on ubuntu
What I did to get out of the first wall I was assigned to the SRE team and bumped into, "What should I start with?"
[Docker] When I did docker-compose build, I got an error saying Can not read file. .. [Rails 6.0]
When I run docker-compose exec in crontab, I get "the input device is not a TTY"
What I was addicted to when introducing the JNI library
What to check when rails db: migration does not pass
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
What I did when I stumbled on IntelliJ gradle 2.2 → 2.6 environment migration
What I was addicted to with the Redmine REST API
How to get the log when install4j does not start
[AWS] What I'm glad I did with my first deployment
I want to pass the startup command to postgres with docker-compose.
The story I was addicted to when setting up STS
When I try to use the AWS SDK with Ruby + Lambda, `sam local` is messed up.
What to do if the app is not created with the latest Rails version installed when rails new
[java] What I did when comparing Lists in my own class
What Docker beginners did before setting up the nginx learning environment
What to do when the changes in the Servlet are not reflected
About what I did when creating a .clj file in Clojure
What I did in the migration from Spring Boot 1.4 series to 2.0 series
What I was addicted to when implementing google authentication with rails
I checked because the response was strange when debugging with Tomcat 8
What I did in the migration from Spring Boot 1.5 series to 2.0 series
[Note] How to restart the Windows container set up with docker-compose
What I often do when I have trouble naming with Java (etc.)
The story that the build error did not stop when using Eclipse 2020
Docker test DB does not start
I want to docker-compose up Next.js!
Precautions when creating PostgreSQL with docker-compose
What I learned with Java Gold
mysql doesn't start up with docker.
What I did when I was addicted to the error "Could not find XXX in any of the sources" when I added a Gem and built it
What I learned with Java Silver
[IOS] What to do when the image is filled with one color
I tried running the Angular sample in Auth0 Quick Start with Docker
Memorandum: What I was addicted to when I hit the accounting freee API
Problems I was addicted to when building the digdag environment with docker
Specify the favorite IP of the host network with docker-compose and start it
Notes on what to do when EC2 is set up with t2.micro
I was stuck with the handling of the time zone when formatting with SimpleDateFormat
When I try to sign up with devise, it automatically redirects to root_path
After verifying the Monty Hall problem with Ruby, a story that I could understand well and did not understand well
What did I prepare for when I entered an Android application development project while developing the Web in Java?