Effects of confinement and environment on the electronic structure and exciton binding energy of MoS2 from first principles