Docker exec Linux终端创建别名 [英] Docker exec linux terminal create alias
问题描述
我有一个正在运行的独立容器。在连接到该容器之前,我想在此创建一个命令别名。
I have a running and detached container. I want to create a command alias there before attaching to that container.
当我连接到该容器并输入以下内容时:
When I am attached to the container and I type:
alias bar='foo'
an别名已创建,并可能由以下人员检查:
an alias is created, and might be checked by:
alias
命令。
但是如果我想通过 docker exec 命令执行相同的操作即以这种方式
but if I want to do the same by docker exec command ie this way
docker exec -it <container-name> /bin/bash -c "alias bar='foo'"
它不起作用,可能是因为当我连接到容器并在其终端中键入
it does not work, probably because when I'm attached to the container and type into its terminal
/bin/bash -c "alias bar='foo'"
效果不佳。
您知道如何修改 alias bar ='foo'
使其与 docker exec
命令一起使用吗
Do you know how to modify alias bar='foo'
so it works together with docker exec
command applied to a detached container?
推荐答案
内置的 alias
创建别名在当前外壳中。别名(如环境变量)不会持久保存,只能加载。您需要更新.bashrc或容器内部的任何内容,以具有所需的别名,以便可以在bash的每次启动时加载它。
The alias
built-in creates an alias in the current shell. Aliases, like environment variables, are not persisted, only loaded. You need to update your .bashrc or whatever inside the container to have the desired alias so that it can be loaded on each start of bash.
这篇关于Docker exec Linux终端创建别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!