Set correct env variables for `docker exec` commands

Fix #9155, #9044