Table of Contents
How to mount external volumes in Docker
Docker is an OS-level virtualization tool that allows us to run non-native software packages via containers. By default, external volumes are not mounted in Docker. We will in this guide show how they can be mounted on computers running macOS.
Before getting started we will download a sample image in order to be able to follow along this tutorial. We will use Alpine Linux because it weighs only 5 MBs.
Let us download the image by running the following command in a terminal:
docker image pull alpine
Alpine Linux should be downloaded within seconds.
Mounting via the command line
We are now ready to run the Alpine Linux container and mount our external volume.
For this example, let us assume that we just want to access some files on an external USB drive.
To achieve this, we will need to supply the
docker command with a
-v /source:/destination flag.
Here is the complete command:
docker container run -it -v /Volumes/usb:/mnt/usb alpine /bin/sh
This will run Alpine Linux in an interactive terminal and mount the USB drive in /Volumes/usb/ onto the destination /mnt/usb. If we browse to the mounted directory and list its contents we can see that the files exist.
Mounting via the Docker UI
If you prefer not to use the command line it is also possible to mount volumes directly from within the Docker Desktop UI. Here is how to do it:
Open Docker Desktop, select Images in the left hand column, locate the container image and press the Run button.
Press the down arrow to expand the Optional Settings tab. Fill in the path to the external volume under Host Path and type in the destination path under Container Path. Press Run to launch the container.
Once the container is up and running we can open its Command Line Interface (CLI) by pressing the round button highlighted in red.
This will open a new terminal inside the Alpine Linux container. If we now browse to the mounted directory and list its contents we can see the files that exist on our USB drive.
This guide has shown how external volumes can be mounted inside Docker, via the command line, or the user interface.
To learn more about Docker, visit:
You can also type
docker in a terminal to get a list of available command line arguments.
$ docker Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/Users/hackintosh/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/Users/geekbitzone/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/Users/geekbitzone/.docker/cert.pem") --tlskey string Path to TLS key file (default "/Users/geekbitzone/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds config Manage Docker configs container Manage containers context Manage contexts image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container deploy Deploy a new stack or update an existing stack diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.
comments powered by Disqus
- Which components can be upgraded on my Mac?
- How to hide external disk drives from the desktop in macOS
- How to upgrade rsync in macOS
- How to change the startup programs in macOS
- How to install Nextcloud on Mac with Docker
- How to extend the lifespan of memory cards on the Raspberry Pi with Log2Ram
- How to measure the network speed between two computers with iPerf
- How to turn your Raspberry Pi into a Jukebox
- How to connect to GitHub with SSH
- How to compile OpenEmu for macOS