How to Share Files Between Mac and Linux Containers with Apple container Volumes and Mounts
Purpose
This post demonstrates how to share files between macOS and Linux containers, create persistent named volumes, and manage storage with Apple container.
Host Directory Mounts
Mount a directory from my Mac into a container:
container run --volume ~/Desktop/assets:/content/assets my-imageThe equivalent using --mount:
container run --mount source=${HOME}/Desktop/assets,target=/content/assets my-imageChanges on either side are visible immediately. This is useful for development β edit files on the Mac, run them inside the container.

Named Volumes
Create a persistent volume:
container volume create myvolume --opt journal=orderedVolume driver options include:
size: limit the volume size (e.g.10g)journal: ext4 journaling mode βordered(default),writeback, orjournal
Attach it to a container:
container run -v myvolume:/data my-imageNamed volumes survive container restarts and persist even after the container stops.
Anonymous Volumes
Without a source, Apple container auto-creates an anonymous volume:
container run -v /data my-imageAnonymous volumes get UUID-based names like anon-{uuid}. Unlike Docker, they do NOT auto-cleanup with --rm. I need to remove them manually.

Volume Management
container volume lscontainer volume inspect myvolumecontainer volume rm myvolumecontainer volume pruneSSH Agent Forwarding
The --ssh flag mounts the macOS SSH agent into the container:
container run --ssh my-imageThis is equivalent to:
container run \ --volume "${SSH_AUTH_SOCK}:/run/host-services/ssh-auth.sock" \ --env SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock \ my-imageUseful for cloning private git repositories from inside the container.

Summary
| Volume type | How to create | Persistence |
|---|---|---|
| Host bind mount | --volume /host:/container | Host filesystem |
| Named volume | container volume create v + -v v:/path | Survives restarts |
| Anonymous volume | -v /path (no source) | Survives, no auto-cleanup |
In this post, I showed how to mount host directories, create named volumes, and manage storage with Apple container. The syntax is Docker-compatible, with the addition of ext4 journaling options for named volumes.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- π¨βπ» Apple container Volume Documentation
- π¨βπ» OCI Runtime Specification Mounts
Oh, and if you found these resources useful, donβt forget to support me by starring the repo on GitHub!
Comments