Repository navigation
Description
I have done the following
- I have searched the existing issues
- If possible, I've reproduced the issue using the 'main' branch of this project
Steps to reproduce
- Format an external drive as APFS and mount it at
/Volumes/MacStorage. - Create a directory on the external volume:
sudo mkdir -p /Volumes/MacStorage/services/gitlab. - Attempt to run a container with a bind mount from the external volume:
sudo container run -d \ --name gitlab-test \ -v /Volumes/MacStorage/services/gitlab:/var/opt/gitlab \ -p 8080:80 \ gitlab/gitlab-ce:latest
- Observe the container logs:
You will see permission denied errors when the container attempts to write to
sudo container logs gitlab-test
/var/opt/gitlab.
Expected Behavior:
The container should start successfully and be able to read/write to the bind-mounted directory on the external APFS volume, just as it would with a native volume or a bind mount on the internal drive.
Actual Behavior:
The container fails to initialize. Logs show errors like:
Permission denied @ dir_s_mkdir - /var/opt/gitlab/...Unable to create directory: /var/opt/gitlab/...- Files created in the bind mount are owned by
root:rootinside the container, even though the host directory is owned by the admin user.
Diagnostic Output:
# Host: Directory ownership is correct
ls -ld /Volumes/MacStorage/services/gitlab
# drwxr-xr-x 2 rdev admin 64 Jun 25 10:00 /Volumes/MacStorage/services/gitlab
# Container: Shows ownership as root
sudo container exec gitlab-test ls -ld /var/opt/gitlab
# drwxr-xr-x 2 root root 64 Jun 25 14:00 /var/opt/gitlab
# Container: Cannot write to directory
sudo container exec gitlab-test touch /var/opt/gitlab/testfile
# touch: cannot touch '/var/opt/gitlab/testfile': Permission deniedProblem description
When attempting to run a container with its root filesystem or bind-mounted volumes located on an external APFS volume, the container fails to start or access files due to persistent permission and ownership errors. The issue occurs even when the external volume is formatted as APFS and has correct ownership at the macOS level. The container process inside the VM cannot properly read/write to the mounted path, often defaulting to root ownership (UID 0) which conflicts with the container's user namespace.
Additional Context:
- The issue persists regardless of the
--userflag orchowncommands inside the container. - The same container configuration works when the bind mount is on the internal drive (
/Users/Shared/...). - The external volume is not using Time Machine or other special filesystem features.
- This blocks the ability to use external storage for container data, which is a common need for development and production environments.
Potential Root Cause:
The virtiofs mount between the macOS host and the Linux VM may not correctly propagate ownership/permissions from APFS volumes, or the container runtime may not properly map UIDs/GIDs when the source is on an external drive. This differs from native volumes which are managed by the container runtime and stored in a location it controls.
See also:
I found several related issues, but none that clearly and exactly match the problem:
| Issue | Title | Relevance |
|---|---|---|
| #890 | Add ability to use external storage (USB drives, SSDs) for container | Requests general external storage support, but doesn't report a specific failure or permission error. |
| #621 | "container system start" hangs when app root is placed on an external drive | Reports a hang (not a permission error) when the application root is on an external drive, which is different from my scenario where the container's filesystem volume is on an external drive. |
| #15 | Postgres container fails to initialize when bind-mounting data | Reports permission errors (UID/GID mismatch) with bind mounts, which is similar to my permission issues, but it's specific to Postgres and doesn't mention external drives. |
| #565 | Cannot use a relative path as the source path of a bind mount | About path parsing, not external drive permissions. |
note: GLM helped me to document the issue, and urged me to file it here when I asked for advice ("This issue is important because it affects the fundamental ability to use external storage with containers—a critical feature for many use cases. Filing it will help the Apple team understand and prioritize the problem."). chatGPT was used to systematize the demonstration locally.
Environment
- macOS: 26.5.1 BuildVersion: 25F80
- Apple Containers CLI: 1.0.0 (build: release, commit: ee848e3)
- Container Image: GitLab CE (gitlab/gitlab-ce)
- Storage: External APFS volume on /dev/disk6s1 mounted at /Volumes/MacStorageCode of Conduct
- I agree to follow this project's Code of Conduct
Activity
danielsyauqi commentedon Jun 26, 2026
The
root:rootownership inside the container is expected here — it's coming from the external volume having "Ignore ownership on this volume" enabled (the default for non-boot APFS drives), not from a virtiofs/UID-mapping bug.Note that the directory was created with
sudo mkdir, so its real on-disk owner isroot. With ignore-ownership on, the hostlsmasks that and displays it as your user (rdev:admin) — but virtiofs reads the real metadata and propagatesuid 0into the VM, which is what GitLab then can't write to. The internal-drive path (/Users/Shared) works because ownership is enabled there, so the real owner is preserved end-to-end.To confirm and fix:
Also worth avoiding
sudo mkdir(it creates root-owned dirs) and reconsidering whethersudo containeris needed at all.In short: virtiofs is faithfully surfacing the ownership that the host UI was hiding — there's no UID-mapping defect. This is macOS volume-ownership behavior rather than a
containerbug, though it might be worth a docs note or a warning when a bind-mount source lives on an ignore-ownership volume.robbiemu commentedon Jun 26, 2026
Thank you. I had checked Sharing and permissions but apparently it doesn't always render there: since it also shows specific users (and we had configured these) I assumed this was disabled. Checking this way I see I had misdiagnosed it:
diskutil info /Volumes/MacStorage | grep -i owners Owners: DisabledI believe this could be the issue (I will come back once more to verify after I'm done , possible reshaping my set up to use a real user instead of root), at least the basis for the solution is not just hypothesis.robbiemu commentedon Jun 26, 2026
Yes, thanks for the detailed explanation! That uncovered a real misconfiguration and the mechanics of how
virtiofssurfaces that masked metadata make more sense to me now. But it does not resolve the issue.To give a little context on why this is running in the root/system scope: GitLab is managed as a boot-time LaunchDaemon (
/Library/LaunchDaemons/org.srvmini2.gitlab.plist). It needs to start before GUI login and survive user sessions. I previously tested running Apple Container under a dedicatedgitlabmacOS user, but that only worked while the user had an active Aqua/GUI session. After logout, thegui/507bootstrap domain disappeared and theUserName=gitlabLaunchDaemon could not bootstrap or talk tocontainer-apiserver, failing with an XPC connection error. So usingsudo launchctl bsexec / /usr/local/bin/container ...is the service-management model for this unattended deployment, not an attempt to work around the MacStorage ownership issue.Your ownership tip was spot on. I enabled ownership on the external volume and confirmed it:
I set up an isolated path (
/Volumes/MacStorage/services/gitlab-canary/data) and explicitlychowned it to my host user/group (502:20). At this point, the external APFS volume has ownership enabled, and the bind-mount source is a real directory owned by the expected user.However, the container still fails before it even starts—so I never actually get to run the
touch,chmod, or UID tests inside the VM. It fails during bootstrap with this error:This also happens if the user not only owns the folder but even the drive (via
sudo chmod -a "remove allow list,search,readattr,readextattr,readsecurity" /Volumes/MacStorage,sudo chmod -a "remove allow list,search,readattr,readextattr,readsecurity" /Volumes/MacStorage/services).So we have now ruled out:
removeACL on the drive rootremoveACL on/Volumes/MacStorage/servicesThe failure is still at Apple Virtualization’s directory-sharing bootstrap layer.
So it looks like there were actually two layers here:
For now, I’m keeping GitLab on native Apple Container volumes, since external APFS bind mounts still appear to be blocked at the Virtualization directory-sharing layer even with ownership enabled and the source directory correctly chowned.
Thanks again for pointing me in the right direction on the ownership piece!
Jakeshadow commentedon Jun 30, 2026
We ran into this too. External APFS volumes mounted into containers need explicit permissions in the container run command. The key settings:
--volume /Volumes/ExternalDrive/data:/data— basic mount--security-opt label=disableif SELinux-like restrictions applyFull volume permission patterns (including the external drive edge cases) at maccontainer.dev/installation/ — the Step 2 troubleshooting section covers common volume failures.
If you're using a non-default APFS volume, also check that the volume isn't mounted with ownership disabled (
mount -o ownersif needed).robbiemu commentedon Jul 11, 2026
Update: chatGPT 5.6 Sol found and deployed a workaround for a parallel project (ie same structure and issue), but the original external APFS directory-bind failure remains unresolved.
Enabling ownership corrected the initially masked ownership metadata discussed above. Even afterward, directly bind-mounting a directory beneath
/Volumes/...continued to fail during VM bootstrap with:The working design bypasses that
virtiofsdirectory-sharing path:volume.imgis a direct regular file inside an APFS sparsebundle physically stored on the external drive.virtio-blk, rather than sharing an external host directory throughvirtiofs.volume.img. If the external backing is absent, attachment fails instead of silently consuming internal storage.I validated this progressively:
container-apiserver;This passed on macOS 26.5.1 with Apple Container 1.0.0.
This is an implementation-detail integration that must be revalidated after Apple Container upgrades. It is not evidence that external directory bind mounts now work, and first-class external-storage support would still be valuable (and much preferred). I am leaving this issue open because the originally reported
virtiofsbootstrap failure is still reproducible; this comment only records a viable block-device workaround for workloads that can use a native named volume.