基本上就像您经常做的那样,将其添加到用户的
.bashrc:
FROM fooRUN echo 'alias hi="echo hello"' >> ~/.bashrc
和往常一样,这仅适用于交互式外壳:
docker build -t test .docker run -it --rm --entrypoint /bin/bash test hi/bin/bash: hi: No such file or directorydocker run -it --rm test bash$ hihello
对于非交互式外壳,您应该创建一个小脚本并将其放在路径中,即:
RUN echo -e '#!/bin/bashnecho hello' > /usr/bin/hi && chmod +x /usr/bin/hi
如果您的别名使用参数(即
hi Jim->
hello Jim),则只需添加
"$@":
RUN echo -e '#!/bin/bashnecho hello "$@"' > /usr/bin/hi && chmod +x /usr/bin/hi



