【问题标题】:Different result after run command between shell script and terminalshell脚本和终端之间运行命令后的不同结果
【发布时间】:2020-09-16 13:06:55
【问题描述】:

情况

使用 shell 脚本将 docker 镜像(Nodejs 应用)推送到 ECR

命令

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin xxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com

文件外壳脚本

#!/bin/sh

docker build -t abc/abc-api ../../abc/abc-api

docker build -t abc/abc-fe ../../abc/abc-fe

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com

docker tag abc/abc-api xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:api-latest

docker push xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:api-latest

docker tag abc/abc-fe xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:fe-latest

docker push xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:fe-latest

当前

  • 运行文件shell脚本时
Unable to locate credentials. You can configure credentials by running "aws configure".
Error: Cannot perform an interactive login from a non TTY device
  • 在终端上运行命令时
WARNING! Your password will be stored unencrypted in /home/***/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

我想要什么

Shell 脚本登录成功

环境

  • Linux mint 20
  • aws-cli 2.0.46
  • aws configure 配置的 aws 身份验证

【问题讨论】:

  • 你能解释一下“销售脚本”和“终端”是什么意思吗?
  • 我刚刚更新了文件shell脚本和一些描述
  • 什么时候执行你的shell脚本?
  • 它显示根...
  • 因此,当您在终端中运行命令时,您使用的用户与您自己不同。这就解释了为什么它不起作用。

标签: amazon-web-services sh amazon-ecr


【解决方案1】:

基于 cmets。

脚本不工作的原因是它在root用户下执行。 root 用户没有定义 aws 配置文件,这解释了为什么脚本会出错并显示“您可以通过运行“aws configure”消息来配置凭据。

为了纠正这个问题,有一些可能性:

  1. 不要在 root 用户下运行脚本。以您自己的用户身份运行它,因为您已经为自己配置了 aws 配置文件(首选)。
  2. 为 root 用户创建新的 aws 配置文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多