Thermodynamics and stochastic dynamics of transport in confined media