Vietnam's northern provinces carries passengers and cargo mostly between Hanoi

It's the kind of shot every Instagram connoisseur yearns for: century-old railway tracks cutting through dusty backstreets, flanked by tourists drinking beer or iced tea mere inches from the slow-moving trains.

The sight has become such a draw in the Vietnamese capital of Hanoi that authorities have set a weekend deadline for the removal of dozens of cafes that have cropped up, citing safety concerns.

"I love it. It's crazy, and completely different to anywhere I've been before," said Australian tourist Laura Metze, after a train rumbled by.

"I can also see why they would close it down because it's pretty dangerous."

Built in 1902 under French colonial rulers, the railway to Vietnam's northern provinces carries passengers and cargo mostly between Hanoi and the eastern city of Haiphong, and the remote towns of Lang Son and Lao Cai, on the mountainous border with China.

It uses an old-fashioned French narrow gauge, and is so old that when North Korean leader Kim Jong Un visited Hanoi in February for a summit with U.S. President Donald Trump, he had to stop at the border and continue by car.

In Hanoi, the line brushes the rear of houses and shops as it snakes through the city's dense centre. Vendors stroll on the tracks, selling snacks on skewers, while some visitors sit on the railway lines and soak in the vibe.

In recent months, crowds of tourists have gathered along the railway to snap selfies with passing trains or lounge at trackside cafes.

On Sunday, a train had to make an emergency stop soon after leaving Hanoi railway station to avoid hitting tourists, state media said.

The next day, the city's governing body ordered the cafes removed by Saturday to "ensure traffic safety", at the request of the transport ministry.

"Though the railway cafes attract tourists, they are, in fact, violating some regulations," Ha Van Sieu, a government tourism official, told media on Tuesday.

New and creative tourism products are encouraged, but must conform to legal regulations, Sieu added.

Vietnam received 12.87 million foreign visitors in the first nine months of this year, up nearly 11% on the year, government data shows.