This is the procedure for changing the time zone in Docker of Oracle Database.
The following article was very helpful for the procedure for installing Docker in Oracle Database. Using Oracle Database with Docker
For the detailed procedure, please refer to the official repository. https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/README.md
All you have to do is set the environment variable TZ in docker-compose.yaml.
version: '2'
services:
db:
image: oracle/database:12.1.0.2-se2
container_name: oracle
ports:
- 1521:1521
- 5500:5500
volumes:
- ./oradata:/opt/oracle/oradata
environment:
- ORACLE_PWD=Oracle01
- ORACLE_PDB=pdb01
- TZ=Asia/Tokyo ★★★ This ★★★
(*) Below, I will leave a memorandum of the investigation process. It's completely snake-footed, so please see only those who are interested.
While using Docker for Oracle Database, I noticed that the result of executing the SYSDATE
function was UTC.
When I connected to the container with docker exec and hit the date command, it was UTC as expected.
$ date
Sat Feb 1 15:07:28 UTC 2020
To change the time zone of the Linux server, you can use timedatectl (RHEL7 series / CentOS7 series) or copy the time zone configuration file (/ usr / share / zoneinfo).
When I checked the OS information, it was RHEL 7.7.
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.7 (Maipo)
When I try to hit timedatectl in the container, I get an error.
$ timedatectl
Failed to create bus connection: No such file or directory
After investigating, I found information that it may be caused by the execute permission of the container, and it may be solved by setting privileged mode (privileged) or changing the capability setting. , Could not be resolved. (*) If anyone knows the information, it would be helpful if you could let me know.
Therefore, I decided to deal with it by copying the time zone configuration file.
#You can also set a symbolic link
# ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
cp: cannot create regular file '/etc/localtime': Permission denied
I was angry because of lack of permissions, so I log in to the container as the root user.
PS > docker exec -it --user root {Container name} /bin/bash
OCI runtime exec failed: exec failed: container_linux.go:346: starting container process caused "chdir to cwd (\"/home/oracle\") set in config.json failed: permission denied": unknown
An unclear error has occurred. .. .. When I googled, I found an article that corresponds to a similar phenomenon.
According to the article, you should use the --workdir
option to overwrite the WORKDIR
setting in the Dockerfile [^ 1], so I'll give it a try.
PS > docker exec -it --user root --workdir / {Container name} /bin/bash
bash-4.2# cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
bash-4.2# date
Sun Feb 2 21:55:24 JST 2020
It went well. However, in this case, it is easier to change the environment variable TZ, so I think it is better to practice that.
[^ 1]: It seems to be caused by the fact that WORKDIR / home / oracle
is specified in the Dockerfile that is the source of the image. (https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/dockerfiles/12.2.0.1/Dockerfile#L105)
Recommended Posts