[Error resolution] Occurs when trying to build an environment for spring with docker

Purpose

** Error ** </ font> has occurred. I encountered it when I built a development environment with Docker. Don't forget the error statement and solution

Conclusion

It turns out that the previously created container will not disappear unless you delete it with a command instead of a project I did not know the cause of the error in the port number.

Status

It occurred when trying to build an environment for java spring with docker. I included Flyway as a migration tool.

** [Environment construction] ** </ font>

$ docker-compose up -d
Starting vi_bank_db_1 ... error
ERROR: for vi_bank_db_1  Cannot start service db: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use
$ lsof -i :3306 → Nothing is displayed

** Error ** </ font>

ERROR: for db  Cannot start service db: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.
$ docker-compose down
WARNING: Found orphan containers (vi_bank_flyway-repair_1, vi_bank_flyway-info_1, vi_bank_flyway-migrate_1, vi_bank_flyway-clean_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Removing vi_bank_db_1 ... done
Removing network vi_bank_default
$ docker-compose up -d --remove-orphans
Creating network "vi_bank_default" with the default driver
Removing orphan container "vi_bank_flyway-migrate_1"
Removing orphan container "vi_bank_flyway-repair_1"
Removing orphan container "vi_bank_flyway-info_1"
Removing orphan container "vi_bank_flyway-clean_1"
Creating vi_bank_db_1 ... error

ERROR: for vi_bank_db_1  Cannot start service db: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use

ERROR: for db  Cannot start service db: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use

Explanation </ font>

Found orphan containers Note that there are already containers in the same project. It seems that the container that I made by myself before remained. It's my first time developing with Docker, so it will be a learning experience. This seems to be the reason why docker-compose up -d is not executed. Execute the command according to the error

$ docker-compose up -d --remove-orphans

** [Solution] ** </ font>

--Changed the port number from 3306 to 3307

docker-compose.yml



version: '3.7'
services:
  db:
    image: mysql:8.0.20
    ports:
      - "3307:3306"

afterwards

$ docker-compose up -d
Recreating vi_bank_db_1 ... done
$ docker-compose exec db mysql -u docker -p
Password entry → Success
mysql>

** Error encountered ** </ font> ERROR: for vi_bank_db_1 Cannot start service db: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use

approach

$ lsof -i :3306
#Nothing is displayed
$ docker-compose up -d
Recreating vi_bank_db_1 ... done

Update 201108

Error resolution </ font>

The java version of Gradle could not be set.

image.png

Referenced article (Thank you always)

Using MySQL with Docker [docker container run option]

Error starting userland proxy: listen tcp0.0.0.0:3306: bind: address already in use

Recommended Posts