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

如何在Docker for Mac镜像中访问共享文件夹?

Accessing Docker for Mac Shared Folders from Inside a Container (After SSHing In)

Hey there! Let me break down exactly how to get to those shared folders you set up in Docker for Mac's "File Sharing" preferences once you're logged into your container via SSH.

Step 1: Confirm Your Shared Folders Are Enabled

First, double-check that you've actually selected the folders you want to share in Docker for Mac:

  • Open Docker for Mac, go to Preferences > File Sharing
  • Make sure the checkbox next to your target folder (like /Users/your-username or a custom directory) is checked
  • Click "Apply & Restart" if you made changes

Step 2: Mount the Shared Folder When Starting the Container

The key thing here is that Docker won't automatically make your shared folders available inside the container—you need to explicitly mount them when you launch the container using the -v (volume) flag.

For example, if you want to share your local /Users/your-username/dev folder and access it at /app inside the container, run your container like this:

docker run -d -p 22:22 --name my-dev-container -v /Users/your-username/dev:/app your-image-name
  • -p 22:22 maps the container's SSH port to your host (so you can SSH into it)
  • -v /host/path:/container/path creates the mount between your shared host folder and the container directory

Step 3: Access the Folder After SSHing In

Once you SSH into the container (e.g., ssh user@localhost -p 22), you can navigate directly to the mounted path you specified:

cd /app
ls

You'll see all the files from your host's shared folder right there!

Troubleshooting Tip: Permissions

If you run into permission errors, it's usually because the user inside the container doesn't have access to the mounted directory. A quick fix is to adjust the permissions on the host side, or specify the user when running the container with the --user flag (e.g., --user $(id -u):$(id -g) to match your host user's UID/GID).


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:39:43