And how do you stop a ship if you consider it a biohazard and don’t want it to get near your dock (and also don’t have the equipment to safely board it without effectively throwing your sailors’ lives away), but it’s insistently coming in anyway? (Perhaps because it’s a “ship of the dead”, drifting unmanned toward your port. Or because it’s, say, just a big barge carrying a pile of tires that’s on fire.)
...would a sufficient number of depth charges work?
You wouldn't you'd just let them try to dock and not supply any personnel to take the docking lines. If they try to do it by sending their own folks to shore, you arrest them as if you would arrest any other trespasser. If it is an empty ship, you take some tugboats and redirect it to sea or whatever.
The military is a lot less militant than you'd think. At least in the Navy, we train hard for everything but we also ensure that we use force correctly and in proportion. We would never try to shoot at or harm a bunch of civilians, they're the people we were trying to protect, Americans or not. Maybe not every branch thinks like that, or things have changed in ~10 years I've been out, but I'd like to think any professional Navy would act the same.
This is an astonishingly contrived hypothetical. If it's drifting and for some reason you magically cannot board the ship, you get on the radio and ask for a tug.