当我通过 ssh 运行此命令到 aws 实例时
docker run hello-world
aws ecr get-login --no-include-email --region ap-south-1 > ./login
source ./login
Run Code Online (Sandbox Code Playgroud)
它输出
Run Code Online (Sandbox Code Playgroud)WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
我通过添加用户
Run Code Online (Sandbox Code Playgroud)sudo usermod -a -G docker jenkins sudo usermod -a -G docker user
出了什么问题?
source不是标准 shell 命令;它不是POSIX.1 规范中的“特殊内置实用程序”之一。有些 shell 碰巧有一个名为 的命令source,但并不要求它存在。
有一个类似的标准命令 .可以在当前 shell 的上下文中执行文件。如果您使用的是特定于 bash 的source,通常可以将其更改为标准,.而无需进行任何进一步的更改
. ./login
Run Code Online (Sandbox Code Playgroud)
注意.搜索$PATH要运行的文件;除非特别告知,否则它不会搜索当前目录。另请注意,您通常仅用于.具有副作用(例如设置环境变量)的脚本,并且在类似于您显示的每个命令在单独的 shell 中运行的上下文中,这不会产生更持久的效果。
由于该命令的输出aws ecr get-login是单个docker login命令,不会直接更改 shell 上下文,因此您也可以将其作为 shell 脚本运行
sh ./login
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4240 次 |
| 最近记录: |