Duplicate app icons in the Dock

Solution 1:

I don't have a specific answer as to what causes macOS to do this, however there is an issue on the VS Code GitHub repository which has lots of discussions about this (for VS Code app at least).

It seems to have something to do with launching an app directly (executing the binary inside XYZ.app/Contents/MacOS) instead of via Launch Services (the open command).

Solution 2:

Passing the -n flag when using the open command opens multiple instances of an app. For example, running open -n -a Terminal several times will open multiple instances of the terminal app, as seen below

Terminals