Short answer: System Settings › Desktop & Dock, then turn off Show suggested and recent apps in Dock.
From the command line:
defaults write com.apple.dock show-recents -bool false; killall Dock
The Dock keeps a separate section on the right, after the divider, holding up to three apps you have opened recently that are not already in the Dock. They are not pinned and you did not put them there. They appear, push everything else along, and disappear again.
That shifting is why people describe it as the Dock rearranging itself. Nothing you placed has moved; a temporary section has grown next to it.
On macOS 26 this lives in Desktop & Dock. On older versions it was Dock & Menu Bar, and before that the Dock pane in System Preferences. The wording has barely changed.
defaults write com.apple.dock show-recents -bool false
killall Dock
Without killall Dock the value is written and nothing happens, which is the single
most common reason a command copied from a blog appears not to work. See
what killall Dock does.
To put it back, use -bool true, or
defaults delete com.apple.dock show-recents to return to the macOS default.
This is the version most people arrive looking for and rarely find written down. On a shared Mac, a lab machine or a kiosk, turning the setting off in one account does nothing for the next person who logs in, because it is a per user preference.
Two options that do hold:
com.apple.dock payload applies to every user it targets and cannot be switched back on
from System Settings. This is what MDM does, and it is what an administrator actually wants.defaults write com.apple.dock contents-immutable -bool true stops the Dock's contents
being changed at all, including by dragging. It does not remove the recents section on its own, so
set show-recents to false first, then lock.Order matters. Locking the contents first freezes the Dock with the recents section still enabled.
No. It stops the Dock displaying recently used apps. Nothing is uninstalled, and the apps still appear in Launchpad, Spotlight and the Applications folder.
A macOS upgrade can reset preferences that were never explicitly written. If you set it from Terminal or in a profile it survives; if you only toggled it once years ago it may not. Locking the Dock's contents afterwards is what makes it stick.
Yes.
show-recents in the com.apple.dock domain, delivered as a managed
preference. Because it is managed, the switch in System Settings is grayed out rather than merely set,
which is the behavior an administrator is usually after.
If you would rather not keep a list of commands, Still Dock is the same four settings as switches, and it remembers the Dock you had before you locked it. The size lock is free.