简体   繁体   English

当我尝试使用 Dockerfile 登录 AWS CLI 时出现问题

[英]Issues when I try to login in to AWS CLI using a Dockerfile

I'm trying to sync a file between a Docker container to an AWS Bucket, but I´m having issues when I´m trying to log in or run the first parameters.我正在尝试将 Docker 容器与 AWS 存储桶之间的文件同步,但是当我尝试登录或运行第一个参数时遇到问题。 I´m constantly getting this message:我不断收到这条消息:

usage: aws [options] [...] [parameters] To see help text, you can run:用法:aws [options] [...] [parameters] 要查看帮助文本,您可以运行:

aws help aws help aws help aws 帮助 aws 帮助 aws 帮助

aws: error: argument command: Invalid choice, valid choices are: aws:错误:参数命令:无效的选择,有效的选择是:

I don´t know what I´m doing wrong in my file.我不知道我在文件中做错了什么。 This is my Dockerfile :这是我的Dockerfile

FROM openjdk:11-jre-slim-buster
COPY ./target/AWS-Writer-Test-0.0.1-SNAPSHOT.jar AWS-Writer-Test-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","AWS-Writer-Test-0.0.1-SNAPSHOT.jar"]

FROM amazon/aws-cli
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG AWS_REGION

RUN aws ecr get-login-password --no-include-email | bash
RUN aws s3 cp s3://AWS-Writer-Test/logs/log.txt /log.txt --recursive

#ENTRYPOINT [ "aws", "ecr get-login-password --no-include-email | bash" ]

Any idea what could be my mistake?知道我的错误是什么吗? Thanks for your support.谢谢你的支持。

PS: PS:

  • The final goal is to sync the log files from the Docker Container to the S3 Bucket .最终目标是将日志文件从 Docker 容器同步到 S3 存储桶
  • This is not a public image .不是公众形象 The info is going to be stored in a private repo, inaccessible from the Internet, only accessible through the Intranet.该信息将存储在一个私人仓库中,无法从 Internet 访问,只能通过 Intranet 访问。 However, I´m planning to use some secrets in AWS later, but first I have to make it work.但是,我计划稍后在 AWS 中使用一些秘密,但首先我必须让它工作。

It is important to understand the difference between the two syntax versions which are described in the documentation https://docs.docker.com/engine/reference/builder/#entrypoint .了解文档https://docs.docker.com/engine/reference/builder/#entrypoint中描述的两个语法版本之间的区别非常重要。

You have actually a mixture of both of them.你实际上是两者的混合物。

ENTRYPOINT has two forms: ENTRYPOINT 有两个 forms:

The exec form, which is the preferred form: exec 形式,这是首选形式:

ENTRYPOINT ["executable", "param1", "param2"] The shell form: ENTRYPOINT ["executable", "param1", "param2"] shell 形式:

ENTRYPOINT command param1 param2 ENTRYPOINT 命令 param1 param2

Your ENTRYPOINT is [ "aws", "ecr get-login-password --no-include-email | bash" ] so it runs directly (probably with something like execve() aws command without any shell (that is important) and it tries to feed aws with just one parameter and that is everything together ecr get-login-password --no-include-email | bash .您的ENTRYPOINT[ "aws", "ecr get-login-password --no-include-email | bash" ]所以它直接运行(可能使用类似execve() aws 命令的东西,没有任何shell (这很重要),它尝试仅使用一个参数来提供 aws,这就是所有内容ecr get-login-password --no-include-email | bash

The correct syntax would be ["aws","ecr","get-login-password","--no-include-email"] .正确的语法是["aws","ecr","get-login-password","--no-include-email"] The rest of it:它的rest:

| bash | bash , particularly the '|' | bash ,特别是'|' pipe symbol has no meaning, because it is a shell expression. pipe 符号没有意义,因为它是一个shell表达式。 And you decided to run no shell (by choosing the first version of the ENTRYPOINT syntax), so you cannot use any shell commands/expressions like if for example.而且您决定不运行 shell(通过选择ENTRYPOINT语法的第一个版本),因此您不能使用任何 shell 命令/表达式,例如if

If you need to use the shell, then you need to run the shell version of the ENTRYPOINT, so your syntax would be:如果您需要使用 shell,那么您需要运行 shell 版本的 ENTRYPOINT,因此您的语法为:

ENTRYPOINT aws ecr get-login-password --no-include-email | bash

I would suggest to you to try all three versions and see the difference among the error messages (or the lack of them).我建议您尝试所有三个版本,看看错误消息之间的区别(或缺少它们)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM