리눅스
도커 컨테이너에서 타임존을 설정하는 방법
변군이글루
2020. 10. 27. 16:27
반응형
도커 컨테이너에서 타임존을 설정하는 방법(timezone)
현재 타임존 확인
timedatectl
타임존 설정(Asia/Seoul)
sudo timedatectl set-timezone Asia/Seoul
심볼릭 링크(/etc/localtime 파일을 직접 설정)
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
docker run 명령을 통한 타임존 설정
컨테이너를 실행할 때 환경 변수를 사용하여 타임존을 설정할 수 있습니다.
docker run -it --rm -v /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro centos bash
$ docker run -it --rm -v /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro centos bash
[root@5574276d2005 /]# date
Tue Oct 27 16:20:02 KST 2020
Docker Compose를 통한 타임존 설정(volume 마운트)
Docker Compose를 사용하여 타임존을 설정할 때는 docker-compose.yml 파일에서 환경 변수를 설정하거나 볼륨을 마운트할 수 있습니다.
vim docker-compose.yml
version: '3.8'
services:
centos:
container_name: centos
entrypoint: bash -c "while [ 0 ]; do sleep 2; done"
hostname: centos
image: centos
restart: on-failure
volumes:
- /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro
$ docker-compose ps
Name Command State Ports
----------------------------------
centos /bin/bash Up
$ docker-compose exec centos bash
[root@centos /]# date
Tue Oct 27 16:31:35 KST 2020
vim docker-compose.yml
version: '3.8'
services:
centos:
container_name: centos
hostname: centos
image: centos
restart: on-failure
stdin_open: true # docker run -i
tty: true # docker run -t
volumes:
- /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro
$ docker-compose ps
Name Command State Ports
----------------------------------
centos /bin/bash Up
$ docker-compose exec centos bash
[root@centos /]# date
Tue Oct 27 16:31:35 KST 2020
vim docker-compose.yml
...
stdin_open: true # docker run -i
tty: true # docker run -t
728x90
반응형