Looks pretty much like the ship you dock to is registered in another sector.
As you play single player, mark the ship you want to dock to, and type:
/teleport_selected_to 0 0 0
and then teleport away from the sector for 30 seconds and come back.
This will relocate the physical part of the ship to the new location as well.
After this the docking should work properly.
You may have been building close to a sector border and passed it.
(Same problem happens when you build a station over a sector border, the docking request gets processed in the wrong sector and you end up stuck far away from the ship, until undocking again.)
- Andy