You can use the dd command to backup the entire Raspberry Pi SD card on Mac.
If you simply read the entire SD card with dd, a huge image file for the entire capacity of the SD card will be created, including the unused area. This squeezes your storage capacity and takes a long time to restore to an SD card.
So I tried to reduce the size of the image file using a Docker container with a tool called PiShrink. This article explains the procedure.

Environments

Mac: 10.14.6

Raspberry Pi 3 Model B+

Docker for Mac(docker desktop): 2.1.0.4

Docker container with PiShrink installed

I used turee/pishrink-docker this time. Several similar containers have been published on the Docker Hub, but unverified.

Deleting unnecessary applications, software packages

Before creating an SD card image, delete unnecessary applications and software packages. Insert the SD card you want to create an image file into your Raspberry Pi and power it.

Deleting unnecessary applications

sudo apt-get purge libreoffice wolfram-engine sonic-pi scratch

Be careful not to accidentally delete the apps you are using!

Deleting unnecessary software packages

sudo apt-get clean
sudo apt-get autoremove

Creating an SD card image file

Shut down the Raspberry Pi and remove the SD card. Connect the SD card to your Mac. Then, run diskutil list command on your command line to find the location of the SD card device file.

In the above example, it's OK to use the path /dev/disk3 where the SD card is mounted on. On the other hand, You can use another device file named /dev/rdisk3 which is also created for the SD card. Reading and writing via /dev/rdiskX is faster than via /dev/diskX since /dev/rdiskX is not buffered, but /dev/diskX is buffred on the other hand("r" for "rdisk" means "raw").

It is supported to mount a volume of the host machine to the Docker container when executing docker run, but an error occurred when PiShrink tried to run with the directory of the backed-up SD card image file which is in the host filesystem.

To avoid this error, we need to copy the original image file to the container and compress it, then copy the compressed file to the host side again.
If only one argument (the path of the original source image file) is specified for pishrink command, the original file is overwritten with the compressed file.

Finally, let's compress the pishrinked-image file withxz command.
Although it depends on the contents of the SD card image, the pishrinked-file that was 3.7GB was compressed to about 1.1GB.

$ xz XXXX.img
load: 2.88 cmd: xz 30200 running 58.35u 0.42s

As with the dd command, typing Ctrl + T while the xz command is running will display the progress.
If only the compression source file name is specified in the xz command arguments, the original file will be replaced with the compressed file.
The name of the file will be the same as the original file but the .xz extension will be added to its tail.

Writing compressed SD card image file

Booting Raspberry Pi with compressed SD card image

The partition will be expanded to the full free space on the SD card at the first boot.

Conclusion

The procedure to reduce the size of the SD card image file of Raspberry Pi using a tool called PiShrink installed in Docker container have explained. Smaller image files save storage space and require less writing time, so I recommend that you compress after creating a backup from a large SD card.