๐[Docker] Docker & MySQL
๋จผ์ Docker์์ MySQL์ ์คํ์์ผ๋ณด์
๋์ปค ๋ฒ์ ํ์ธ
$ docker -v
Docker version 20.10.10 build b485636
MySQL ์ด๋ฏธ์ง pull ๋ฐ๊ธฐ
$ docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
8b0617b3cebc: Pull complete
16ae022566ed: Pull complete
eecd18f4775b: Pull complete
556cfab8150e: Pull complete
ce811470e9ce: Pull complete
c2d2c48356cf: Pull complete
ada74d40ba87: Pull complete
3b7b27488bbe: Pull complete
7c89304473a0: Pull complete
0be02980a719: Pull complete
Digest: sha256:0f2e15fb8b47db2518b1428239ed3e3fe6a6693401b2cf19552063562cfc2fc4
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
Docker image ๋ฆฌ์คํธ ํ์ธ โ image pull์ด ๋๋์ง!
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest [image_id] 6 days ago 723MB
mysql latest [image_id] 2 weeks ago 638MB <-- mysql!
httpd latest [image_id] 2 months ago 194MB
Docker MySQL ์ปจํ ์ด๋ ์์ฑ ๋ฐ ์คํ
$ docker run --name [์ปจํ
์ด๋ ์ด๋ฆ] -e MYSQL_ROOT_PASSWORD=[MYSQL ์ ๊ทผ ๋น๋ฐ๋ฒํธ] -d -p 3306:3306 mysql:latest
# ์์
$ docker run --name mysqldb -e MYSQL_ROOT_PASSWORD=1234 -d -p 3306:3306 mysql:latest
-d
: ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํ์ด ๊ฐ๋ฅํ๊ฒ ํ๋ ์ต์ -e
: ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ๊ธฐ ์ํด ์ฌ์ฉ โMYSQL_ROOT_PASSWORD
์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํจ-p
: ํฌํธ ์ค์ โ[HOST_PORT]:[CONTAINER_PORT]
์คํ ์ค์ธ Docker ์ปจํ ์ด๋ ํ์ธ
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[์ปจํ
์ด๋_id] mysql:latest "docker-entrypoint.sโฆ" 35 minutes ago Up 2 seconds 33060/tcp, 0.0.0.0:2206->3306/tcp mysqldb
์ปจํ ์ด๋ ์์ํ๊ธฐ
$ docker start [์ปจํ
์ด๋_์ด๋ฆ]
์ปจํ ์ด๋ ์ข ๋ฃํ๊ธฐ
$ docker stop [์ปจํ
์ด๋_์ด๋ฆ]
์ปจํ ์ด๋ ์ฌ์์
$ docker restart [์ปจํ
์ด๋_์ด๋ฆ]
์ปจํ ์ด๋ ์ ์ โ MySQL Shell๋ก ์ ์ฅ!
$ docker exec -it [์ปจํ
์ด๋_์ด๋ฆ] /bin/bash
์ปจํ ์ด๋ ์ญ์
$ docker rm [์ปจํ
์ด๋_์ด๋ฆ]
Docker image ์ญ์
$ docker rmi [image_id] or [image_name]
์ฐธ๊ณ ์๋ฃ
[Docker] Docker๋ฅผ ์ฌ์ฉํ์ฌ Mysql ์ปจํ ์ด๋ ์์ฑํ๊ณ ์ ์ํ๊ธฐ
๋๊ธ๋จ๊ธฐ๊ธฐ