관리 메뉴

IT.FARMER

docker mysql timezone 기준 시간대 변경 본문

devops/docker

docker mysql timezone 기준 시간대 변경

아이티.파머 2018. 10. 12. 15:39
반응형

기준 시간대를 변경하는 방법은 두가지가 있다.

 

이미 docker 로 mysql를 띄운상태에서 타임존을 바꿔야할 경우 컨네이너에 접속하여  지역 및 타임존을 변경 하는 방법과 ,   처음부터 docker 를 실행할때 환경설정란에 타임존을 넣은 상태에서 실행 시키는 방법이다.

 

1. Docker Container Bash  Timezone 설정

#컨테이너 접속
> docker exec -it d14292ef0736 /bin/bash

# 지역 선택 후 아시아 서울 지정 

> tzselect
> export TZ='Asia/Seoul'


#. profile 에 적용
TZ='Asia/Seoul'; export TZ   #<<< 마지막 줄에 추가

 

 

2. Docker Run Timezone 설정

 

mysqldb:
    #image: mysql:5.7.21
    build: .
    #container_name: mysql_container
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - TZ=Asia/Seoul

 

3. volumes link 방법 

volumes:
    # 우분투 타임존
    - "/etc/timezone:/etc/timezone:ro" 
    # Cent OS 타임존
    - "/etc/localtime:/etc/localtime:ro"

 

3.1 docker run 에서 link

docker run [other parameters] -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime

 

 

4. 결과 확인

4.1  Mysql 접속 후 테이블 정보로 확인시 

타임존이 잘등록되었는지 확인한다. 

select 
	b.name
	, a.time_zone_id  
from mysql.time_zone a, mysql.time_zone_name b 
where a.time_zone_id = b.time_zone_id 
and b.name like '%Seoul';

 

4.2 Docker mysql bash  에서 확인할 경우 

[root@test sss]# docker exec -it d14292ef0736 /bin/bash

root@d14292ef0736:/# mysql -u root -p

Enter password: 

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

root@d14292ef0736:/# mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 13

Server version: 5.7.21 MySQL Community Server (GPL)



Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.



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> SET GLOBAL time_zone='Asia/Seoul';;

Query OK, 0 rows affected (0.00 sec)



mysql> set time_zone='Asia/Seoul';

Query OK, 0 rows affected (0.00 sec)





mysql> SELECT @@global.time_zone, @@session.time_zone, @@time_zone;
반응형

'devops > docker' 카테고리의 다른 글

Dockerfile command / Attribute 명령어 설명  (0) 2019.06.21
docker 기본 명령어 및 설명  (1) 2019.06.21
docker- compose [cassandra / mysql]  (0) 2019.06.05
Docker 기본 명령어  (0) 2018.04.24
Docker 설치 & Docker Sonarqube 설치  (0) 2017.09.04