1. Docker CLI 로 컨테이너 실행
$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pwd123 -v /Users/jint/docker-mysql/mysql_data:/var/lib/mysql mysql
2. Docker Compose 로 MySQL 실행
1) compose.yml 파일 작성
- compose-practice/compose.yml
services:
my-db:
image: mysql
environment: # -e MYSQL_ROOT_PASSWORD=password 역할
MYSQL_ROOT_PASSWORD: pwd123
volumes: # v {호스트 경로}:/var/lib/mysql 역할
- ./mysql_data:/var/lib/mysql
ports:
- 3306:3306
#1 environment: 환경변수설정
컨테이너의 환경 변수 설정
CLI 에서 "-e" 옵션 역할과 동일
#2 volumes: - 호스트 디렉토리 절대경로:컨테이너 디렉토리 절대경로
볼륨을 사용할 호스트와 컨테이너의 절대경로 지정
CLI 에서 "-v" 옵션 역할과 동일
2) compose 파일 실행
- Windows PowerShell
PS C:\Users\admin> cd .\compose-practice\
PS C:\Users\admin\compose-practice> docker compose up -d
[+] up 15/15
✔ Image mysql Pulled 19.7s
✔ Network compose-practice_default Created 0.0s
✔ Container compose-practice-my-db-1 Started 1.0s
What's next:
Filter, search, and stream logs from all your Compose services
in one place with Docker Desktop's Logs view. docker-desktop://dashboard/logs?appId=compose-practice
3) compose 실행 현황 확인
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
compose-practice-my-db-1 mysql "docker-entrypoint.s…" my-db 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp
PS C:\Users\admin\compose-practice> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d55e3fbb12a3 mysql "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp compose-practice-my-db-1
4) 컨테이너 로그 확인
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose logs
my-db-1 | 2026-05-27 14:00:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.7.0-1.el9 started.
my-db-1 | 2026-05-27 14:00:48+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
my-db-1 | 2026-05-27 14:00:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.7.0-1.el9 started.
my-db-1 | 2026-05-27 14:00:48+00:00 [Note] [Entrypoint]: Initializing database files
my-db-1 | 2026-05-27T14:00:48.739143Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
my-db-1 | 2026-05-27T14:00:48.740224Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 9.7.0) initializing of server in progress as process 81
my-db-1 | 2026-05-27T14:00:48.747003Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
my-db-1 | 2026-05-27T14:00:48.758090Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
my-db-1 | 2026-05-27T14:00:49.757559Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
my-db-1 | 2026-05-27T14:00:51.928532Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
my-db-1 | 2026-05-27T14:00:55.085765Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
my-db-1 | 2026-05-27 14:00:55+00:00 [Note] [Entrypoint]: Database files initialized
my-db-1 | 2026-05-27 14:00:55+00:00 [Note] [Entrypoint]: Starting temporary server
my-db-1 | 2026-05-27T14:00:55.138877Z 0 [System] [MY-015015] [Server] MySQL Server - start.
my-db-1 | 2026-05-27T14:00:55.351426Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 9.7.0) starting as process 127
my-db-1 | 2026-05-27T14:00:55.351438Z 0 [System] [MY-015603] [Server] MySQL Server has access to 20 logical CPUs.
my-db-1 | 2026-05-27T14:00:55.351447Z 0 [System] [MY-015603] [Server] MySQL Server has access to 33578602496 bytes of physical memory.
my-db-1 | 2026-05-27T14:00:55.354048Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
my-db-1 | 2026-05-27T14:00:55.370613Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
my-db-1 | 2026-05-27T14:00:56.261136Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
my-db-1 | 2026-05-27T14:00:56.811377Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
my-db-1 | 2026-05-27T14:00:56.811582Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
my-db-1 | 2026-05-27T14:00:56.823610Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
my-db-1 | 2026-05-27T14:00:56.873865Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
my-db-1 | 2026-05-27T14:00:56.873959Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '9.7.0' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
my-db-1 | 2026-05-27 14:00:56+00:00 [Note] [Entrypoint]: Temporary server started.
my-db-1 | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
my-db-1 |
my-db-1 | 2026-05-27 14:00:58+00:00 [Note] [Entrypoint]: Stopping temporary server
my-db-1 | 2026-05-27T14:00:58.721373Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 9.7.0).
my-db-1 | 2026-05-27T14:01:00.190920Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 9.7.0) MySQL Community Server - GPL.
my-db-1 | 2026-05-27T14:01:00.190953Z 0 [System] [MY-015016] [Server] MySQL Server - end.
my-db-1 | 2026-05-27 14:01:00+00:00 [Note] [Entrypoint]: Temporary server stopped
my-db-1 |
my-db-1 | 2026-05-27 14:01:00+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
my-db-1 |
my-db-1 | 2026-05-27T14:01:00.735675Z 0 [System] [MY-015015] [Server] MySQL Server - start.
my-db-1 | 2026-05-27T14:01:00.937696Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 9.7.0) starting as process 1
my-db-1 | 2026-05-27T14:01:00.937709Z 0 [System] [MY-015603] [Server] MySQL Server has access to 20 logical CPUs.
my-db-1 | 2026-05-27T14:01:00.937717Z 0 [System] [MY-015603] [Server] MySQL Server has access to 33578602496 bytes of physical memory.
my-db-1 | 2026-05-27T14:01:00.940998Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
my-db-1 | 2026-05-27T14:01:00.952819Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
my-db-1 | 2026-05-27T14:01:01.880735Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
my-db-1 | 2026-05-27T14:01:02.302787Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
my-db-1 | 2026-05-27T14:01:02.303045Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
my-db-1 | 2026-05-27T14:01:02.317557Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
my-db-1 | 2026-05-27T14:01:02.390524Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
my-db-1 | 2026-05-27T14:01:02.390598Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '9.7.0' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
What's next:
Filter, search, and stream logs from all your Compose services
in one place with Docker Desktop's Logs view. docker-desktop://dashboard/logs?appId=compose-practice
5) MySQL 컨테이너 접속 후 컨테이너에서 MySQL에 접근
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker exec -it d55e bash
bash-5.1# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 9.7.0 MySQL Community Server - GPL
Copyright (c) 2000, 2026, 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> help
For information about MySQL products and services, visit:
https://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
https://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command, if enabled
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
query_attributes Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up.
ssl_session_data_print Serializes the current SSL session data to stdout or file
For server side help, type 'help contents'
mysql> exit
Bye
bash-5.1# exit
exit
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug d55e
Learn more at https://docs.docker.com/go/debug-cli/
6) DataGrip 에 연결
데이터베이스 탐색기 우클릭 > 새로 작성 > 데이터 소스 > MySQL > MySQL
호스트: localhost
사용자: root
비밀번호: pwd123
연결 테스트 성공 후, "적용" 버튼 클릭 후 "확인" 버튼 클릭

7) MySQL 데이터가 볼륨에 저장되는지 확인
- Windows PowerShell
PS C:\Users\admin\compose-practice> ls
디렉터리: C:\Users\admin\compose-practice
Mode LastWriteTime Length Name
---- ------------- ------ ----
da---- 2026-05-27 오후 11:01 mysql_data
-a---- 2026-05-27 오후 10:54 294 compose.yml
PS C:\Users\admin\compose-practice> cd mysql_data
PS C:\Users\admin\compose-practice\mysql_data> ls
디렉터리: C:\Users\admin\compose-practice\mysql_data
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2026-05-27 오후 11:01 #innodb_redo
d----- 2026-05-27 오후 11:01 #innodb_temp
d----- 2026-05-27 오후 11:00 mysql
d----- 2026-05-27 오후 11:00 performance_schema
d----- 2026-05-27 오후 11:00 sys
-a---- 2026-05-27 오후 11:00 4194304 #ib_16384_0.dblwr
-a---- 2026-05-27 오후 11:00 12582912 #ib_16384_1.dblwr
-a---- 2026-05-27 오후 11:00 56 auto.cnf
-a---- 2026-05-27 오후 11:00 2997943 binlog.000001
-a---- 2026-05-27 오후 11:01 198 binlog.000002
-a---- 2026-05-27 오후 11:01 32 binlog.index
-a---- 2026-05-27 오후 11:00 1705 ca-key.pem
-a---- 2026-05-27 오후 11:00 1108 ca.pem
-a---- 2026-05-27 오후 11:00 1108 client-cert.pem
-a---- 2026-05-27 오후 11:00 1705 client-key.pem
-a---- 2026-05-27 오후 11:01 12582912 ibdata1
-a---- 2026-05-27 오후 11:01 12582912 ibtmp1
-a---- 2026-05-27 오후 11:00 5723 ib_buffer_pool
-a---- 2026-05-27 오후 11:01 32505856 mysql.ibd
-a---l 2026-05-27 오후 11:00 0 mysql.sock
-a---- 2026-05-27 오후 11:00 124 mysql_upgrade_history
-a---- 2026-05-27 오후 11:00 1705 private_key.pem
-a---- 2026-05-27 오후 11:00 452 public_key.pem
-a---- 2026-05-27 오후 11:00 1108 server-cert.pem
-a---- 2026-05-27 오후 11:00 1705 server-key.pem
-a---- 2026-05-27 오후 11:03 16777216 undo_001
-a---- 2026-05-27 오후 11:03 16777216 undo_002
8) compose 로 실행된 컨테이너 중지 후 삭제
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose down
[+] down 2/2
✔ Container compose-practice-my-db-1 Removed 1.3s
✔ Network compose-practice_default Removed 0.3s
PS C:\Users\admin\compose-practice> docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
PS C:\Users\admin\compose-practice> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
비전공자도 이해할 수 있는 Docker 입문/실전| JSCODE 박재성 - 인프런 강의
현재 평점 4.9점 수강생 14,484명인 강의를 만나보세요. 비전공자 입장에서도 쉽게 이해할 수 있고, 실전에서 바로 적용 가능한 Docker 입문/실전 강의를 만들어봤습니다! Docker 기본 개념, Spring Boot를
www.inflearn.com
'강의 실습 > 비전공자도 이해할 수 있는 Docker 입문 실전' 카테고리의 다른 글
| [실습] Docker Compose로 백엔드(Nest.js) 실행시키기 (0) | 2026.05.29 |
|---|---|
| [실습] Docker Compose로 백엔드(Spring Boot) 실행시키기 (0) | 2026.05.29 |
| [실습] Docker Compose로 Redis 실행시키기 (0) | 2026.05.26 |
| 자주 사용하는 Docker Compose CLI 명령어 (0) | 2026.05.25 |
| [실습] Docker Compose 전체 흐름 느껴보기 (Nginx 설치 및 실행) (0) | 2026.05.23 |
댓글