반응형
docker에 mysql를 설치하자!
1, docker 설치 확인
- OS가 window면 콘솔창을 열자.
$ docker -v
Docker version 25.0.2, build 29cf629
2. docker 에 mysql 이미지 만들기
$ docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
81badc5f380f: Pull complete
c490e5dd1a9d: Pull complete
87aeb61f1478: Pull complete
1cacbea6ceda: Pull complete
1e72891ace67: Pull complete
42b720363d36: Pull complete
6b3b50f9990a: Pull complete
3811d52cfa61: Pull complete
05bc7a0277d8: Pull complete
cc0abd25a274: Pull complete
Digest: sha256:ff5ab9cdce0b4c59704b4e2a09deed5ab8467be795e0ea20228b8528f53fcf82
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
3. docker 이미지 리스트
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest a88c3e85e887 4 weeks ago 632MB
4. docker 에 mysql 컨테이너 생성하고 실행하기
# docker run --name <컨테이너명> -e <환경변수> -d -p <호스트 포트>:<컨테이너 포트> <사용이미지>
--name : 컨테이너명
-e : 환경변수설정
-d : detach 모드, 컨테이너 백그라운드 실행
-p : 포트연결
$ docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=1111 -d -p 3306:3306 mysql:latest
c69f693f130ffe82bb932144157dabf3fb21cd8f346bd176d8cffaeabcf8da0a
- docker desktop 에서 컨테이너가 running 인 것을 확인할 수 있다.
5. docker 컨테이너 리스트 출력
D:\>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c69f693f130f mysql:latest "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-container
6. mysql 컨테이너 접속
# docker exec -it <컨테이너명> bash
$ docker exec -it mysql-container bash
bash-4.4#
7. mysql 접속
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.3.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
8. mysql 컨테이너 중지/시작/재시작
$ docker stop mysql-container
mysql-container
$ docker start mysql-container
mysql-container
$ docker restart mysql-container
mysql-container
9. 컨테이너 삭제
# docker rm <컨테이너명>
# or
# docker rm <컨테이너ID>
# 1. 동작중인 컨테이너 확인
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c69f693f130f mysql:latest "docker-entrypoint.s…" 16 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-container
# 2. 컨테이너 중지
$ docker stop mysql-container
mysql-container
# 3. 동작중인 컨테이너 확인
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 4. 컨테이너 삭제
$ docker rm mysql-container
mysql-container
# 5. 모든 컨테이너 확인
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
10. docker image 삭제
# docker rmi <레파지토리명>
# or
# docker rmi <레파지토리명>:<태그>
# or
# docker rmi <이미지ID>
# 1. 이미지 확인
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest a88c3e85e887 4 weeks ago 632MB
# 2. 이미지 삭제
$ docker rmi mysql:latest
Untagged: mysql:latest
Untagged: mysql@sha256:ff5ab9cdce0b4c59704b4e2a09deed5ab8467be795e0ea20228b8528f53fcf82
Deleted: sha256:a88c3e85e887d78c6c16ee6a0a6297e09bd573193918a08f269a942ddad77856
Deleted: sha256:a47e3f5184188d0ded58167f81ed399bda838b37716d6a0d9fb538ae64371767
Deleted: sha256:750ea5242272cdbf344d0af35c4eff64c7b0296491bf9747214d4012c4feb391
Deleted: sha256:2f17d48c81db0969179826d20d81e1cd333676a714e293a19a6fdaa2d57b1f27
Deleted: sha256:bea3f162c4bd2492d6cfce9f715c60a61020205e82647343034c33c2d2c1c720
Deleted: sha256:d3ad25eecba2cc8f5d837c5436fd4ce2230c51c6a6b206125b9dba76f83bd02f
Deleted: sha256:8fb5524227094d3e8963e8bb93af8835a5928f34a072e2272aaf330b00fc3a58
Deleted: sha256:3dcdcc4db1094b30a257b6feb414db6149934171333bc8c6ea543578021862ac
Deleted: sha256:706b673eebeed9bc92da642eee3a1f5ea076e149b98491624ce7436ee40d115d
Deleted: sha256:ed862c4f3420f8cdf5fb1160305a714585ffd0cc739c6f6306c750e82d50cd75
Deleted: sha256:55d310cc1793fd699f7389585b86d5ff0270ad8f516f81db295e51e12f6d0b5b
끝.
반응형
'IT > WSL' 카테고리의 다른 글
docker compose - jenkins, github 연동 (0) | 2024.03.31 |
---|---|
docker compose - nginx 설치 및 설정 (0) | 2024.03.30 |
AWS EC2 인스턴스 생성 및 트러블 슈팅 (0) | 2024.03.30 |
WSL에 도커(Docker)를 설치하자. (0) | 2024.02.28 |
WSL 을 설치해보자 (0) | 2024.02.20 |
윈도우용 도커(Docker)를 설치하자. (0) | 2024.02.14 |
[Linux] TMOUT=0 / 세션 타임 아웃 설정 (0) | 2023.06.05 |
[Linux] vi 편집기에서 문자열 찾기 (0) | 2022.12.30 |
프로세스 확인 명령어 (0) | 2022.07.06 |
중요 디렉토리 (0) | 2020.05.13 |