[LINUX] Change the time zone with Docker in Oracle Database


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'
    image: oracle/database:
    container_name: oracle
      - 1521:1521
      - 5500:5500
      - ./oradata:/opt/oracle/oradata
      - ORACLE_PWD=Oracle01
      - ORACLE_PDB=pdb01
      - TZ=Asia/Tokyo ★★★ This ★★★

Record of going back and forth

(*) 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.

Logging in as root on Oracle Database Docker image

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/

Recommended Posts

Change the time zone with Docker in Oracle Database
Reinforcement learning in the shortest time with Keras with OpenAI Gym
Touch NoSQL with Python using the Oracle NoSQL Database Cloud Simulator
I tried to describe the traffic in real time with WebSocket
How to get the date and time difference in seconds with python
I set the environment variable with Docker and displayed it in Python
Let's change the color scheme of iTerm2 automatically depending on the time zone
Get and convert the current time in the system local timezone with python
Find a turning point! [Extracting change points in time series with change finder]
With the advent of systemd-homed in 2020, Linux user management will change dramatically.
Access the Docker Remote API with Requests
Run the IDCF cloud CLI with Docker
Behavior when returning in the with block
Behind the flyer: Using Docker with Python
Set the time zone to Japan Standard Time
Display Python 3 in the browser with MAMP
Change the list in a for statement
MongoDB for the first time in Python
[IOS] Change the display time for each frame of GIF animation in Pythonista3.
Visualize accelerometer information from the microcomputer board in real time with mbed + Python
I was in trouble because the behavior of docker container did not change
Get Unix time of the time specified by JST regardless of the time zone of the server in Python
What I did when I got stuck in the time limit with lambda python
Convert the world time zone time string to Japan time without calculating the time difference with python.
Time zone
Turn multiple lists with a for statement at the same time in Python
Convenient time series aggregation with TimeGrouper in pandas
Log in to the remote server with SSH
Hello World with gRPC / go in Docker environment
[Python] Get the files in a folder with Python
Load the network modeled with Rhinoceros in Python ③
Prepare the execution environment of Python3 with Docker
Start Caddy with docker without putting Caddy in CentOS8
Change the device (drive) label in vfat format.
Change the font size of the legend in df.plot
[Python3] A story stuck with time zone conversion
What is wheezy in the Docker Python image?
[Automation] Extract the table in PDF with Python
Use logger with Python for the time being
I played with Floydhub for the time being
Can't change aspect_ratio with sympy.plotting? About the matter
Read the output of subprocess.Popen in real time
Determine the numbers in the image taken with the webcam
Detect folders with the same image in ImageHash
Start Nginx with docker without putting Nginx in CentOS8
Load the network modeled with Rhinoceros in Python ②
Loop variables at the same time in the template
Try converting videos in real time with OpenCV
Load the network modeled with Rhinoceros in Python ①
The story that fits in with pip installation
Change the reserved words in Flask's template engine
Write this in the ttl file for the time being for automatic SSH login with Teraterm
Output the specified table of Oracle database in Python to Excel for each file