The story that led to solving the error because postgres did not start with docker-compose up

Before installing laravel I wanted to start the container with docker-compose up, but I couldn't

I was learning laravel based on a certain learning material, and it was the content to start the container using PostgreSQL, but since it did not start well, it is a memorandum until error resolution.

The command actually executed

Terminal


 docker-compose up -d workspace php-fpm nginx postgres

It is an option after up, but the postgres attached at the end will be the story this time.

If the container is started successfully,

Terminal


Creating laravel-sns_docker-in-docker_1 ... done
Creating laravel-sns_workspace_1        ... done
Creating laravel-sns_php-fpm_1          ... done
Creating laravel-sns_nginx_1            ... done
Creating laravel-sns_porstgres_1        ... done

It should come out like this, but in my case

Terminal


Recreating laravel-sns_postgres_1 ... error
Creating laravel-sns_docker-in-docker_1 ... done
Creating laravel-sns_workspace_1        ... done
Creating laravel-sns_php-fpm_1          ... done
Creating laravel-sns_nginx_1            ... done

ERROR: for laravel-sns_postgres_1  Cannot start service postgres: Ports are not available: listen tcp 0.0.0.0:5432: bind: address already in use

It looks like this.

Cause

A few months ago, I found out that it was postgres that I had installed when I didn't know much more than it is now.

At that time, I remembered the existence of postgres that I installed without thinking because I wanted to use a DB other than MySQL, and when I looked at the connection status from pgadmin, the port number 5432 shown in this error content was connected It was in a state.

Think of a path to a solution

This time it was an error that occurred while learning a certain teaching material, so when I consulted with the instructor, ・ Ports are not available ・ Address already in use Why don't you search around with keywords? I got the advice, so

Ports are not available → Ports are not available address already in use → The address has already been used Based on the interpretation of the literal translation, I searched and found a hint that seems to be this.

Articles that I was able to refer to https://mebee.info/2020/04/20/post-7968/

Is it possible to kill the process using port number 5432 based on this? I thought and executed immediately

Terminal


sudo lsof -i -P | grep 5432

pgAdmin4   2471 ---------   21u  IPv6 ---------      0t0  TCP localhost:64447->localhost:5432 (CLOSE_WAIT)
* Account names and tokens are hidden.

Now that we know that the process number was 2471,

Terminal


kill 2471

Execute the kill command with

Start the container again

Terminal


 docker-compose up -d workspace php-fpm nginx postgres

Omit the started container
 Starting 8d38216de390_laravel-sns_postgres_1 ... done

I was able to start postgres safely.

When I think about it, I was reminded that postgres, which I had only installed at that time and had never used, was already connected to the server.

I knew the horror of installing this even in an ignorant state, but at that time I didn't even know the kill command at all, so I learned that there are some things that can be solved over time.

It's not a big deal, but if there is even one person in the same situation, it may be useful for something.

Recommended Posts

The story that led to solving the error because postgres did not start with docker-compose up
The story when the container does not start up with docker-compose up and an error occurs
What I did when the DB did not start with docker-compose up
[Docker] The story that an error occurred in docker-compose up
The story that the build error did not stop when using Eclipse 2020
In WSL2, when I did `docker-compose up`, I got an error saying that the sh file was not found.
The story that did not disappear when I tried to delete mysql on ubuntu
I want to pass the startup command to postgres with docker-compose.
The story that the DB connection and other timeouts did not time out according to the set value
[Rails] A story that continued to incorrectly verify the reason why the update action did not pass (update)
How to fix the problem that Aptana Studio does not start
[Gradle] The story that the class file did not exist in the jar file
[Note] How to restart the Windows container set up with docker-compose
Container does not start with docker-compose
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
The story of introducing Gradle as a retrofit to an existing system that did not manage packages
How to interact with a server that does not crash the app
After verifying the Monty Hall problem with Ruby, a story that I could understand well and did not understand well
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
[Error] How to resolve the event that the screen does not transition after editing
[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'-'
Error deploying rails5 + Mysql to heroku with Docker-compose
[Spring Boot] The story that the bean of the class with ConfigurationProperties annotation was not found
Java Error Handling Basics-The story that catch is only picked up in the foreground
A story that did not work when trying to handle events in Notification Center