Permission denied error when building docker image in Mac OS

When building a docker image in Mac OS, i get the folloiwng error message

ERROR: mkdir /Users/username/.docker/buildx/refs/desktop-linux: permission denied

it looks like something changed the owner of that folder.

Make sure thatā€™s the case by running the following command:

ls -lna ~/.docker/buildx/refs

You should see this:

drwx------@ 3 501  20   96 Jul 11 09:42 .
drwx------@ 9 501  20  288 Oct 22 01:44 ..
drwx------@ 3 501  20   96 Jul 11 09:42 desktop-linux

The following commands should return the user id and group id the same as you can see in the 3. and 4. columns.

id -u
id -g

If you can confirm the IDs are different, you can run this command to fix it:

sudo chown -R $(id -u):$(id -g) $HOME/.docker/buildx/refs
1 Like