小编Ser*_*Dub的帖子

为什么 docker exec 命令会在 docker 容器内忽略 bashrc?

所以。我有 ubuntu 的 docker 镜像(也从此镜像创建了容器)。在我的 docker 容器上,我看到以下输出:

root@61ff2a8dbf2d:/# uname -a
Linux 61ff2a8dbf2d 5.3.0-51-generic #44~18.04.2-Ubuntu SMP Thu Apr 23 14:27:18 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

在我的容器上的文件 ~/.bashrc (它是 /root/.bashrc)上,我导出一些变量:

export VARIABLE1="value1"
export VARIABLE2="value2"
Run Code Online (Sandbox Code Playgroud)

当我尝试使用“docker exec”在 docker 容器上执行命令时,我看不到 .bashrc 文件中的变量

root@HUAWEI-MateBook-X:~/Documents/# docker exec -it sly_compilator /bin/bash -c 'export'
declare -x HOME="/root"
declare -x HOSTNAME="61ff2a8dbf2d"
declare -x OLDPWD
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
declare -x PWD="/"
declare -x SHLVL="1"
declare -x TERM="xterm"
Run Code Online (Sandbox Code Playgroud)

为什么我看不到我的变量?如何修复它?

但如果我记录我的容器,效果就很好。

root@HUAWEI-MateBook-X:~/Documents/# docker exec -it sly_compilator bash
root@61ff2a8dbf2d:/# export
declare -x …
Run Code Online (Sandbox Code Playgroud)

linux bash ubuntu docker

9
推荐指数
1
解决办法
3960
查看次数

标签 统计

bash ×1

docker ×1

linux ×1

ubuntu ×1