Remove macOS Dock icon with a command in Terminal
I recommend using dockutil for this. You can either download and install this directly from github, or you can install it using Homebrew with the command

brew install dockutil


Once installed, you can use a command like this to remove an app from the dock

dockutil --remove 'Microsoft Excel'