Reading Time: 3 minutes

I am using a Macbook Pro with 128 GB disk space for 4 years. So, you can imagine the challenge of managing the disk space. On top of it when I have installed Docker, it is really hard to work as I have to check how much disk space left after installing any software. So, I was looking for an easy solution where I can move my docker images to an external drive and still use Docker. I checked few articles and got the idea but the exact instructions did not help. So, I am writing this post with the instructions which worked for me.

1. Find Docker image location

You need to figure out the docker image path by clicking on the advance option of resource in your docker desktop preference.

Go to your terminal and change the directory to the above path:

cd /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data

Inside the data directory, there should be the file Docker.raw which contains the docker images. Type ls to see this file. Also, very the file size by running du -sh command.

2. Quit Docker Desktop

If you have docker running, you need to stop it.

3. Copy your Docker.raw file to an external drive

Connect the SSD(recommended) or hard drive to your mac. Create a folder called Docker and then create a folder called image inside the Docker folder.

Now, we need to move Docker.raw file from Docker image location to above image folder in your external drive.

cd /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data
cp -r Docker.raw /Volumes/TAN_2TB/Docker/image/

It will take a while, so please wait until the process gets completed. Once completed, verify the Docker.raw file size inside your external drive. You might find the file size is more than the original file size. So, don’t worry.

Now remove the Docker.raw file from your Mac. If you want you can take another backup of Docker.raw file inside your Mac before removing it.

cd /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data
rm -rf Docker.raw

4. Create a symlink for Docker virtual image

Run below commands

cd /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data
ln -s /Volumes/TAN_2TB/Docker/image/Docker.raw /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data

Verify symlink gets created or not

ls -la /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data

If you will check the content inside data folder, you will see Docker.raw file should exist and run du -sh command which will show the size as 0B

In future if you want to unlink the symlink and create new symlink you can use the below command

// unlink path-to-symlink

Ex:
unlink /Users/tanmayabiswal/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw

5. Run The Docker Desktop App

Now run the docker desktop app and it will take a while and it should run successfully. If you will create new docker images then it will be added to your external drive.

Reference

https://community.cloudera.com/t5/Community-Articles/How-to-move-Docker-for-Mac-vm-image-from-internal-to/ta-p/247964

Hopefully, it helps you!