If not:
Strong magnifying glass, preferably on a stand.
Strong light, also preferably on a stand.
Pointed end wooden toothpick.
Examine the port for minute (not tiny - so small you can't see them without the magnifying glass) particles between the contacts. If you see one, CAREFULLY roll it out of the connector with the toothpick (and a steady hand).
There are carbide particles in the air. They're metallic (and conduct electricity) but are so small that airflow affects them more than gravity, so they float. If one gets between the wrong contacts, the phone "thinks" it's seeing the "you're docked" short in the dock end of the connector.
Or the docking connector could be loose in its connection to the motherboard, which would be a factory defect, and should be covered under warranty.