Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entering docker container with exec losing PATH environment variable

Here is my Dockerfile:

FROM ros:kinetic-ros-core-xenial
CMD ["bash"]

If I run docker build -t ros . && docker run -it ros, and then from within the container echo $PATH, I'll get:

/opt/ros/kinetic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

If I exec into the container (docker exec -it festive_austin bash) and run echo $PATH, I'll get:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Why are the environment variables different? How can I get a new bash process on the container with the same initial environment?

like image 533
maged Avatar asked Jul 31 '26 16:07

maged


1 Answers

The ENTRYPOINT command is only invoked on docker run, not on docker exec.

I assume that this /ros_entrypoint.sh script is responsible for adding stuff to PATH. If so, then you could do something like this for docker exec:

docker exec -it <CONTAINER_ID> /ros_entrypoint.sh bash
like image 143
Oliver Charlesworth Avatar answered Aug 03 '26 08:08

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!