In the movie, they operated out of Miramar NAS north of San Diego proper.
Most large military bases had rail service into at least the 1970s. Air Force bases and a few large Army bases seemed to keep them the longest, and in many cases the tracks remained (usable) at the time the bases were closed or transferred to local agencies, with some still active (
e.g., the former Castle AFB near Merced). Remaining AF bases (
e.g. Beale) may still have rail connections even if they don't appear to be used much.
The Navy apparently got rid of rail connections long ago (c. 1970 for North Island as described in the Abandoned Rails comments). Could be that unless they needed rail access for big, heavy stuff (i.e. at shipyards), it wasn't worth the effort and expense to keep it. Naval air bases can generally be served on the ground side, for the most part, by road and pipeline. In the case of North Island, also, by barge. Even the big, landlocked naval bases like Lemoore and China Lake gave up rail access a long time ago.
In the Google satellite view for Miramar (Top Gun home for the movie), the land use along Miramar Way beyond the
current end of track (industrial branch from BNSF/NCTD) suggests that the track once continued to the east gate of the base, but traces beyond that are obliterated.