使用 exec 丢失 PATH 环境变量进入 docker 容器 [英] Entering docker container with exec losing PATH environment variable
问题描述
这是我的 Dockerfile:
Here is my Dockerfile:
FROM ros:kinetic-ros-core-xenial
CMD ["bash"]
如果我运行 docker build -t ros .&&docker run -it ros
,然后从容器内echo $PATH
,我会得到:
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
如果我 exec
进入容器 (docker exec -it festive_austin bash
) 并运行 echo $PATH
,我会得到:
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
为什么环境变量不同?如何在具有相同初始环境的容器上获得新的 bash 进程?
Why are the environment variables different? How can I get a new bash process on the container with the same initial environment?
推荐答案
ENTRYPOINT
命令仅在 docker run
上调用,而不在 docker exec
上调用.
The ENTRYPOINT
command is only invoked on docker run
, not on docker exec
.
我假设这个 /ros_entrypoint.sh
脚本负责向 PATH
添加内容.如果是这样,那么你可以为 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
这篇关于使用 exec 丢失 PATH 环境变量进入 docker 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!