작업환경 세팅(feat. 다시 세팅할 때)
PS C:\Users\park7> docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5973fd391691 alpine "ping localhost" 21 months ago Exited (137) 21 months ago exciting_pasteur
PS C:\Users\park7> docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 --name mysql mysql
edfb6978c0b60546a4f6f094eaa7a800938821986be497b4e00a55d1c0ef6909
PS C:\Users\park7> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
edfb6978c0b6 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
CONTAINER ID : edfb6978c0b6
IMAGE : mysql
COMMAND : "docker-entrypoint.s…"
PORTS : 0.0.0.0:3306->3306/tcp, 33060/tcp
NAMES : mysql
여기까지 mysql 정상적으로 실행.(포트 3306까지 셋팅 완료)
아래부터 mysql 데이터베이스 생성이다.
PS C:\Users\park7> docker exec -it mysql bash
bash-4.4# mysql -u root -p
Enter password: 1234(여기서 숫자 입력해도 보이지 않는다.)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.1.0 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> create database stock_example;
Query OK, 1 row affected (0.01 sec)
mysql> use stock_example;
Database changed
노트북 종료 후 다시 프로젝트 시작하려고 할 때
PS C:\Users\park7> netstat -ano | findstr :3306
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 6136
TCP 0.0.0.0:33060 0.0.0.0:0 LISTENING 6136
TCP [::]:33060 [::]:0 LISTENING 6136
PS C:\Users\park7> taskkill /f /pid 6136 → cmd 관리자 모드로 접속
PS C:\Users\park7> docker start mysql → start 다음에 나오는 건 컨테이너 이름(NAMES)
mysql
PS C:\Users\park7> docker start myredis
myredis
PS C:\Users\park7> docker ps
NAMES
myredis
mysql
PS C:\Users\park7> docker exec -it mysql bash
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.1.0 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>