Set correct env variables for `docker exec` commands

Fixes #9155  
Fixes #9044 

This depends on https://github.com/docker/libcontainer/pull/264 to set correct environment variables for exec session and should be rebased when it's merged.