Skip to content

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:

Mount a host directory
container run --volume ~/Desktop/assets:/content/assets my-image

The equivalent using --mount:

Mount with key=value syntax
container run --mount source=${HOME}/Desktop/assets,target=/content/assets my-image

Changes on either side are visible immediately. This is useful for development β€” edit files on the Mac, run them inside the container.

Diagram showing bidirectional file synchronization between a macOS host directory and a Linux container's mount point

Named Volumes

Create a persistent volume:

Create a named volume
container volume create myvolume --opt journal=ordered

Volume driver options include:

  • size: limit the volume size (e.g. 10g)
  • journal: ext4 journaling mode β€” ordered (default), writeback, or journal

Attach it to a container:

Use the named volume
container run -v myvolume:/data my-image

Named volumes survive container restarts and persist even after the container stops.

Anonymous Volumes

Without a source, Apple container auto-creates an anonymous volume:

Anonymous volume
container run -v /data my-image

Anonymous volumes get UUID-based names like anon-{uuid}. Unlike Docker, they do NOT auto-cleanup with --rm. I need to remove them manually.

Timeline diagram comparing named volume and anonymous volume lifecycles across container restarts and removals

Volume Management

List volumes
container volume ls
Inspect a volume
container volume inspect myvolume
Delete a volume
container volume rm myvolume
Remove unused volumes
container volume prune

SSH Agent Forwarding

The --ssh flag mounts the macOS SSH agent into the container:

Forward SSH agent
container run --ssh my-image

This is equivalent to:

Manual SSH agent mount
container run \
--volume "${SSH_AUTH_SOCK}:/run/host-services/ssh-auth.sock" \
--env SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock \
my-image

Useful for cloning private git repositories from inside the container.

Architecture diagram showing SSH agent forwarding from macOS host through socket mount into a Linux container reaching a remote Git server

Summary

Volume typeHow to createPersistence
Host bind mount--volume /host:/containerHost filesystem
Named volumecontainer volume create v + -v v:/pathSurvives 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:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments