You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker无法识别共享路径:/etc/localtime未共享问题求助

Fixing "/etc/localtime not shared from OS X" Error in Docker

Great question—let's break down why this is happening and walk through the fixes:

Why Sharing /private Isn't Enough

First, let's clarify the OS X directory structure here:

  • /etc on OS X is actually a symbolic link to /private/etc—that part you got right.
  • But your /etc/localtime is another symbolic link, pointing to /var/db/timezone/zoneinfo/America/New_York.

The problem? /var is a top-level directory separate from /private, so even though you shared /private, Docker can't access the target of the /etc/localtime link because /var isn't in your shared directories. Docker doesn't automatically resolve cross-directory symlinks outside of shared paths.

Solutions to Try

1. Mount the Actual Timezone File Directly

Skip the middle symlink entirely and mount the real timezone file from your Mac into the container:

docker run -v /var/db/timezone/zoneinfo/America/New_York:/etc/localtime:ro [your-image]

The :ro flag makes it read-only, which is the standard way to mount timezone files.

2. Add /var to Docker's Shared Directories

If you want to keep using the /etc/localtime symlink, add /var to Docker's file sharing list:

  • Open Docker Desktop > Preferences > Resources > File Sharing
  • Click the + button, navigate to /var, and add it
  • Click "Apply & Restart" to save changes

Now Docker can access the /var/db/timezone/... path that /etc/localtime points to, and the symlink will resolve correctly.

3. Use the TZ Environment Variable (Simplest Option)

Most modern Linux-based containers support the TZ environment variable, which lets you set the timezone without mounting any files at all:

docker run -e TZ="America/New_York" [your-image]

This is more reliable than file mounting, as it avoids symlink and file-sharing quirks entirely.

内容的提问来源于stack exchange,提问作者user1079065

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:49:56