Short answer: a Dock that keeps resetting is almost never random. It is one of four things, and three of them you can fix in a minute.
The tell is when it happens: at login, after an update, after unplugging a monitor, or seemingly at random while you work. Each points somewhere different.
This is the most common one, and it usually means the preference file is damaged. macOS reads
com.apple.dock at login, and if it cannot parse the file it falls back to defaults and
writes a fresh one, throwing your layout away every single time.
The fix is to delete it deliberately and let macOS rebuild it clean:
defaults delete com.apple.dock; killall Dock
You lose your pinned apps once, on purpose, and then it stops happening. Set the Dock up again and log out and back in to confirm it held. Full detail in how to reset the Mac Dock. If the icons are in a different order rather than back to factory, see Dock icons rearranged themselves.
If it still resets after that, the preference file is not the problem and something is rewriting it. Keep reading.
Updates can reintroduce Apple's defaults for keys that changed between versions, and the recent applications section is the usual casualty. This one is not damage and does not need the delete above:
defaults write com.apple.dock show-recents -bool false; killall Dock
An update should not move your Dock to another edge or change its size. If it did, that is the damaged-file case rather than the update.
This is not a reset at all, which is why the usual fixes do nothing. macOS decides which display owns the Dock, and moving the pointer to the bottom of another screen hands it over. Nothing has been rewritten; the Dock is simply somewhere else.
There is no defaults key for this. It is the one Dock behavior Apple has never exposed
a setting for, which is why utilities exist to do it. See
keeping the Dock on one screen, and
the apps that do it.
If the size changes and you did not open System Settings, you brushed the divider. The line between your apps and your folders is a drag handle, it sits in the busiest part of the screen, and there is no confirmation and no undo.
The give-away is that everything moved at once: every icon changed size, and every window you had arranged shifted, because the Dock took the space back. That is a resize, not a reset.
The fix is a lock:
defaults write com.apple.dock size-immutable -bool true; killall Dock
The divider stops responding to drags and System Settings grays out the size control. Swap
true for false to undo it.
If none of the above holds, an app is editing com.apple.dock behind you. Backup and
sync tools, "Mac cleaner" utilities, and managed-device profiles from an employer all do this.
To find out whether the file is being rewritten, watch its modification time:
ls -l ~/Library/Preferences/com.apple.dock.plist
If the timestamp moves when you have not touched the Dock, something else is writing. On a work Mac, check System Settings › General › Device Management for a profile, which you cannot override locally and should not try to.
Otherwise, the four immutable keys are what stops another app's write from taking
effect. They are listed in full in
every Mac Dock defaults command.
Only if the cause is another app writing to it. It will not repair a damaged preference file, and the locks themselves live in that same file, so a file that cannot be read loses the locks too. Fix the file first, then lock.
defaults delete com.apple.dock
does, yes. The apps are not touched, only the list of which ones are pinned. Take a screenshot of your
Dock first and it is a two-minute job to put back.
No. iCloud does not sync the Dock between Macs. If your Dock looks like a different Mac's, that came from Migration Assistant or a restore, not from ongoing sync.
Still Dock holds all four Dock settings in place from the menu bar, and remembers the Dock you had before you locked it. Locking the size is free.