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 execute dev@local:~/docker$ 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?

  • in that environment variables are a property of the process (which it can pass to the child process). - aleksandr barakin February
  • @alexanderbarakin added a question. Is there any way to execute any command inside a container with a given environment? Variables are written in /root/.bashrc . - 1d0 am

0