0

I want to run a command outside the container through "exec", which would be executed respectively inside the container. The command runs cmake, which uses environment variables that are already declared when creating the container image.

If I am in the container and execute the env, it gives me a list of all the variables that I need.

root@74b9b0dbbbc9:/# env
LD_LIBRARY_PATH=/usr/local/:
LESSCLOSE=/usr/bin/lesspipe %s %s
HOSTNAME=74b9b0dbbbc9
QT_SELECT=qt5
CC=/usr/bin/gcc
PWD=/
HOME=/root
CXX=/usr/bin/g++
TERM=xterm
SHLVL=1
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/env

And if I run $sudo docker exec -it dever bash -c 'env'

HOSTNAME=74b9b0dbbbc9
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env

What is the reason?

And is it possible through exec (or run) to execute a set of commands with variables that are already set?

  • 2
    you're conflating exec which run a command directly as-is, with a login shell which parse .bashrc and profiles files. That's the reason, for how to solve that, there's many ways but the proper one would be dependent on what you're trying to do. – Tensibai Apr 26 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.