Short answer: macOS has no setting that makes the Dock stay on one screen. The Dock is doing what Apple designed it to do.
There are three workarounds, and every one of them trades away something else. They are below, with the cost of each stated plainly.
The Dock follows your pointer, so no screen owns it. Push the cursor to the bottom edge of any monitor and hold it there for a moment, and the Dock moves to that one. There is no setting anywhere in System Settings that will make it stay put.
The Dock moving between displays is intended behavior, and nothing is broken. On a single display you never notice, because there is nowhere else for it to go. Add a second monitor and the same rule turns into a Dock that appears wherever you last reached for something.
The problem is worse if you keep a browser or a video full screen on the second display, because the bottom edge of that screen is exactly where you go to reach the controls.
System Settings, Desktop & Dock, scroll to Mission Control, and turn off Displays have separate Spaces. Log out and back in.
Your monitors now behave as one large desktop, and the Dock settles on the main display and stays there.
What it costs you. This is the heaviest trade in the list. Each display no longer has its own Spaces, so full-screen apps stop behaving per-screen, and putting a video full screen on one monitor blanks the others. For a lot of multi-monitor setups that is a worse problem than the one you started with.
System Settings, Desktop & Dock, Position on screen, and choose Left or Right.
On a side edge the Dock has far fewer opportunities to be triggered, because you rarely drive the pointer into the outer edge of your monitor arrangement by accident, whereas you cross the bottom edge constantly.
What it costs you. A different Dock layout than you chose. The problem shrinks, though the Dock can still move between screens.
System Settings, Displays, click Arrange, and drag the white menu bar strip onto the display you want as your main one. Apple calls it the main display; most people call it the main screen, and it is the one that holds the menu bar.
Changing the main display sets where the Dock lives by default and where it returns to, so it is worth doing alongside fix 1. The Dock can still move afterward.
Most articles on this problem recommend this:
defaults write com.apple.dock autohide-delay -float 9999999; killall Dock
The idea was to make the delay before the Dock relocates so long it never happens in practice. The trick genuinely worked for years.
On current macOS it is unreliable, and it can do the opposite. Reports since Sonoma describe the Dock moving between displays more often. Even the articles still recommending it now carry that warning. If you have already run it, undo it with:
defaults delete com.apple.dock autohide-delay; killall Dock
The autohide-delay trick is the top result for the problem on several sites, and it is out of date.
The pointer rule explains most cases. Three situations move the Dock without you going near the bottom edge.
After sleep or after unplugging a monitor. When displays disappear and come back, macOS rebuilds the arrangement, and the Dock lands on whichever display is currently main. If your external monitor is slower to wake than the Mac, the built-in screen is briefly the only one there, and the Dock stays on it once the external returns. There is no setting for this. Setting the external as your main display in Displays, Arrange makes it settle in the right place more often, but not always.
Clamshell mode. With the lid shut and the Mac on an external, there is only one screen, so the Dock behaves. Open the lid and you are back to two displays and the pointer rule. If the Dock ends up on the laptop screen the moment you open it, the two displays are the reason.
Sidecar and an iPad as a second display. An iPad counts as a display, so the Dock will move to it. It catches people out because the iPad has its own Dock, and the Mac Dock arriving on top of it looks like a glitch. The behavior is normal.
The same behavior is useful once you know it. To send the Dock to a particular monitor, push the pointer to the bottom edge of that screen and hold it there for a second or two. Push past the edge. The Dock moves across.
If nothing happens, the pointer is probably not far enough down. Keep pushing after the cursor appears to stop, because the trigger sits slightly beyond where it looks like the screen ends.
What people actually want is a setting that says "keep the Dock on this screen", and macOS has never had one. Every fix above works by removing the opportunity.
Still Dock adds that setting. It is an app that locks your Mac's Dock. Pick the display you want the Dock on and it stays there, without turning off separate Spaces, without moving the Dock to an edge you did not choose, and without a Terminal command that stopped working two macOS versions ago.
It is in both the direct download and the Mac App Store version, alongside the locks for size, position, hide and show, and contents.
Hoping for a Dock on every screen? That one has a short answer: can you show the Dock on all screens?
No. macOS shows one Dock, on one screen at a time, and there is no setting or third-party app that changes it. If you searched for how to show the Dock on all screens, that is the answer, and what you are probably seeing is the Dock following your pointer between monitors. This guide is about keeping the Dock on one monitor.
Because displays come back at different speeds. If the external is slower to wake than the Mac, the built-in screen is momentarily the only display, and the Dock stays where it landed. Setting the external as your main display helps but does not fix it every time.
Yes, on any Mac with more than one display. It is standard macOS behavior, and your machine, monitor and cable are fine.
Because full-screen controls sit at the bottom of the screen, so you push the pointer to the exact edge that summons the Dock, which is the most common way people run into the problem.
It changes them significantly. Full-screen apps stop being per-display, and one app going full screen can blank your other monitors. Try it for a day before committing to it.
No, that is a separate problem with a separate cause, the divider being a drag handle. See why your Dock keeps changing size. The Dock also changes size between displays of different densities, which is covered in the monitor guide.
Three apps solve this: DockLock, LockMyDock and Still Dock, built around different problems. DockLock and Still Dock compared covers what each one does, including where DockLock goes further and where LockMyDock fits.