AWS: Docker
我聽說 AWS ECR 支援 Docker 所以決定試試看,但卻發現需要做的事情遠遠超過我的想像。
啊,首先是建立個 Dockerfile。這是整個麻煩裡面最簡單的了。
FROM public.ecr.aws/amazonlinux/amazonlinux:latest
# Install dependencies
RUN yum update -y && \
yum install -y httpd
# Install apache and write hello world message
RUN echo 'Hello World!' > /var/www/html/index.html
# Configure apache
RUN echo 'mkdir -p /var/run/httpd' >> /root/run_apache.sh && \
echo 'mkdir -p /var/lock/httpd' >> /root/run_apache.sh && \
echo '/usr/sbin/httpd -D FOREGROUND' >> /root/run_apache.sh && \
chmod 755 /root/run_apache.sh
EXPOSE 80
CMD /root/run_apache.sh
問題從如何上傳開始。說明上是這麼寫的: aws ecr get-login-password --region {REGION} | docker login --username AWS --password-stdin {AWS_ACCOUNT_ID}.dkr.ecr.{REGION}.amazonaws.com
aws
是什麼?看了下,是 aws 附的 cli 程式,可以管理 aws。我很不想再裝各種東西,但為了上傳,不得不裝呀。
問題是安裝後又收到這個提示:
$ aws ecr get-login-password --region {REGION} | docker login --username AWS --password-stdin {AWS_ACCOUNT_ID}.dkr.ecr.{REGION}.amazonaws.com
> Unable to locate credentials. You can configure credentials by running "aws configure".
> Error: Cannot perform an interactive login from a non TTY device
aws configure
嘛,
$ aws configure
> AWS Access Key ID [None]:
> AWS Secret Access Key [None]:
> Default region name [None]:
> Default output format [None]:
...AWS Access Key ID? AWS Secret Access Key? 哪裡找?
讀了下說明,這兩個似乎需要建立 IAM user 授權。
IAM?啥鬼?我為什麼還要弄個新的東西?但為了 Key ID 不得不幹啊。
我只好去開啟 IAM 授權並建立相對應的 user。應該裡面就有 Key ID 與 Access Key 了吧。
結果我錯了。還需要一連串複雜的登入程序。
我覺得我已經快無法掌握狀況了,只好問 Amazon Q 如何讓 IAM user 登入自己的 cli:
Sorry, I can't answer your question because my response could contain advice related to security or compliance. As these topics are sensitive, I didn't generate an answer. I recommend reviewing the following links or consulting with AWS Support for guidance.
Links
吐血。現在還要讀安全指引就是了?安全指引是還要讀啥?
算了,不幹了。丟一邊去。
怎一個比一個還複雜?
參考資料
- How do I fix the error "Unable to locate credentials" when I connect to my S3 bucket with AWS CLI?
- Configure the AWS CLI
- Configuration and credential file settings - AWS Command Line Interface
- Configure the AWS CLI to use IAM Identity Center token provider credentials with automatic authentication refresh - AWS Command Line Interface
- 管理 IAM 使用者 - AWS Identity and Access Management
- Identity and Access Management (IAM) - Day05 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天
- Introduction to AWS Security Guidance
- Introduction to AWS Compliance