SoFunction
Updated on 2025-03-09

Docker mount /etc/timezone error problem

Docker mount /etc/timezone error

Execute this command

docker run -d --name sys-app  -v /etc/timezone:/etc/timezone  -v 
/etc/localtime:/etc/localtime  -p 8001:8001  --restart=always --net=host 
 sys-app:latest

Report the following error

docker: Error response from daemon: OCI runtime create failed: container_linux.go:346:
 starting container process caused "process_linux.go:449: container init caused 
\"rootfs_linux.go:58: mounting \\\"/etc/timezone\\\" to rootfs 
\\\"/var/lib/docker/overlay2/cb6229f54bfa2ffb1fdb70a316606bf5936ebe69c7d0ee8d26da98b78c9
1e857/merged\\\" at 
\\\"/var/lib/docker/overlay2/cb6229f54bfa2ffb1fdb70a316606bf5936ebe69c7d0ee8d26da98b78c9
1e857/merged/etc/timezone\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying 
to mount a directory onto a file (or vice-versa)? Check if the specified host path 
exists and is the expected type.

Notice:

-v /etc/timezone in docker run command becomes -v /etc/timezone/timezone

The reason is that in centos7.6 /etc/timezone is a folder, not a file

Execute the following command

echo 'Asia/Shanghai' > /etc/timezone/timezone

Then execute

docker run -d --name sys-app  -v /etc/timezone/timezone:/etc/timezone  -v 
/etc/localtime:/etc/localtime  -p 8001:8001  --restart=always --net=host 
 sys-app:latest

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.