개발 이야기/RDBMS
Mysql을 Docker compose로 띄우기
농개
2024. 1. 7. 19:14
반응형
Docker가 이미 설치되었다고 가정하고
Docker Compose를 통해 Mysql를 띄우는 방법을 소개합니다.
1. mysql.conf 파일
# Mysql-specific config file.
# Read by /etc/mysql/my.cnf
[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
#default-character-set = utf8
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
#
# * Character sets
#
# Default is Latin1, if you need UTF-8 set all this (also in client section)
#
#character-set-server = utf8
#collation-server = utf8_general_ci
#character_set_server = utf8
#collation_server = utf8_general_ci
# Import all .cnf files from configuration directory
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
!includedir /etc/mysql/mysql.conf.d/
- /home/mysql/config/mysql.conf
위 파일은 mysql container을 올릴 때 사용할 mysql 환경설정 파일입니다.
필요 케이스에 맞게끔 적절히 수정하여 사용하면 됩니다.
2. docker-compose.yml 파일
version: '3.7'
services:
db:
image: mysql:8.0.22
container_name: mysql_boot
hostname: mysql_boot
restart: always
ports:
- 3306:3306
volumes:
- /home/mysql/data:/var/lib/mysql # data 볼륨 마운트
- /home/mysql/config:/etc/mysql/conf.d # conf 파일이 위치한 디렉토리를 마운트
environment:
MYSQL_ROOT_PASSWORD: root # password 설정
TZ: Asia/Seoul # default timezone
3. 실행
docker-compose -f ./docker-compose.yml up -d
반응형