Accessing persistent volumes in Docker for Mac

If you use persistent data volumes in Docker, and you want to access them with command-line.

If your docker host is Linux, that’s not a problem; you can find Docker volumes by /var/lib/docker/volumes path.

However, that’s not the case when you use Docker for Mac. Try to cd /var/lib/docker/volumes from your MacOS terminal, you ‘ll get nothing.

You see, your Mac machine isn’t a real Docker host. Docker for Mac runs a virtual machine and hides it from you to make things simple.

So, to access persistent volumes created by Docker for Mac, you need to connect on that VM.

In order to accomplish this, we need to use a serial terminal on Mac. There’s a terminal application called “screen” that’s going to help us.

  1. We need to “screen into” the Docker driver by executing a command: screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
  2. You should see a blank screen, just press Enter , and after a while, you should see a command line prompt
  3. Now you’re inside Docker’s VM and you can cd into volumes dir by typing: cd /var/lib/docker/volumes
  4. Profit, you got there!
  5. If you need to transfer files from your MacOS host into Docker host you can refer to File Sharing