I always thought it was a slang term for the men who worked the hammers and drills used for siting the dynamite to blow tunnels through mountains. But that may be imagination.
The OED provides a historical defintion of "terrier" as a collection of acknowledgements of vassals or tenants of a lordship. So we might have a derivation, since many of the Irish who worked the railroads escaped from that kind of vassalage by emigrating. Also, a member of the British territorial Army. Speculation. Anyone have anything more solid??
A