Docker挂载/etc/timezone报错问题
作者:菜菜菜菜菜鸡
Docker挂载/etc/timezone报错
执行这段命令
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
报如下错
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.
注意:
docker run命令中的-v /etc/timezone变成了-v /etc/timezone/timezone
原因是centos7.6中/etc/timezone是一个文件夹,而不是一个文件
执行如下命令
echo 'Asia/Shanghai' > /etc/timezone/timezone
然后执行
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
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。