Error
(docker) Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306: bind: address already in use. 에러 해결과 MySQL 접속
ea_jung
2023. 3. 25. 17:14
맥북 프로 M2를 사용하고 있습니다.
문제 상황
% docker run --name my-database -e MYSQL_ROOT_PASSWORD=root -d -p 3306:3306 mysql:5.7
위의 코드를 실행 시켰는데 아래의 error가 발생했다.
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
326a7772852e86f5513cf7942b39fc90e6c86b05bdefcb5746187a6b1f189597
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306: bind: address already in use.
해결 방법
3306번 port가 사용 중이라 생긴 문제인거 같으므로 먼저 어떤 mysql id가 차지하고 있는지 확인해 봐야 한다.
% sudo lsof -i -P -n | grep 3306
mysqld 2937 _mysql 18u IPv6 0xa58e4dacb0746045 0t0 TCP *:33060 (LISTEN)
mysqld 2937 _mysql 21u IPv6 0xa58e4dacb0742e45 0t0 TCP *:3306 (LISTEN)
2937 id가 차지하고 있음을 확인 할 수 있습니다.
이제 이걸 지워줘야 합니다.
% sudo kill 2937
지워졌는지 확인 하기 위해서 다시 확인해 줍니다.
% sudo lsof -i -P -n | grep 3306
아무것도 안 나타난다면 잘 지워진 거에요.
MySQL 접속하기
컨테이너 name이 있는지 다시 확인 해줍니다.
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
897ccc91cdae mysql:5.7 "docker-entrypoint.s…" 30 minutes ago Up 30 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp my-database
있다고 확인했으면 컨테이너를 start 해줍니다.
$ docker start 컨테이너이름
% docker start my-database
my-database
MySQL 컨테이너 쉘에 진입하기 위해서 아래의 코드를 실행해줍니다.
$ docker exec -i -t 컨테이너이름 bash
% docker exec -i -t my-database bash
bash-4.2#
터미널의 입력 앞 부분이 바뀌면 잘 하고 있는 겁니다.
mysql에 접속하기 위해서 아래와 같이 해줍시다.
bash-4.2# mysql -u root -p
Enter password:
성공했다면 아래와 같이 터미널의 앞부분이 mysql> 로 바뀌었을 거에요!
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
긴 글 읽어주셔서 감사합니다.
-끝-
반응형