The blaze near Cliftonhall Road, Newbridge, Midlothian, started at about 1.30pm and was brought under control by just after 3pm.
Firefighters were concerned that butane gas cylinders close to the fire might explode. Two fire engines attended and there were reports of smoke rising about 100ft in the air. Nobody was injured.
A spokeswoman for Network Rail said two services from Edinburgh to Bathgate were cancelled and a further 12 delayed. Services between Edinburgh and Glasgow continued to run, she said.