The night train from Tbilisi to Baku reaches the border around 2 hours after leaving Tbilisi.
Then, the police gets in and collects everyone's passport. Your bag will be searched for any item related to Armenia (Book, flag, clothes, tickets, etc) and you'll be asked if you ever went to Armenia.
If you're neither Georgian or Azerbaijani you'll be taken to an empty compartment for the formalities (taking your pictures, giving you back your passport and possibly asking you one or two questions).
Azerbaijan and Armenia are in conflict over the Nagorno-Karabakh territory and the relations between the two countries are very tense.
Welcome to Azerbaijan! Azerbaijan is situated at the eastern side of the TransCaucasia on the shores of the Caspian Sea. This is the Land of Fire and the Pearl of the Caucasus, a land where eastern colours, including to unique nature, unmatched culture, centuries of history & its hospitality combine magnificently with western progress.