1 ๋ถ„ ์†Œ์š”

๋จผ์ € 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 ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑํ•˜๊ณ  ์ ‘์†ํ•˜๊ธฐ

ํƒœ๊ทธ: , ,

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ