macos - Docker 无法为 awslogs 日志记录驱动程序提供凭据
问题描述
我的码头工人撰写文件:
version: "2"
services:
app:
build:
# Build an image from the Dockerfile in the current directory
context: .
ports:
- 5000:5000
environment:
PORT: 5000
NODE_ENV: production
和 docker-compose.override
version: "2"
networks:
# This special network is configured so that the local metadata
# service can bind to the specific IP address that ECS uses
# in production
credentials_network:
driver: bridge
ipam:
config:
- subnet: "169.254.170.0/24"
gateway: 169.254.170.1
services:
# This container vends credentials to your containers
ecs-local-endpoints:
# The Amazon ECS Local Container Endpoints Docker Image
image: amazon/amazon-ecs-local-container-endpoints
volumes:
# Mount /var/run so we can access docker.sock and talk to Docker
- /var/run:/var/run
# Mount the shared configuration directory, used by the AWS CLI and AWS SDKs
# On Windows, this directory can be found at "%UserProfile%\.aws"
- $HOME/.aws/:/home/.aws/
environment:
# define the home folder; credentials will be read from $HOME/.aws
HOME: "/home"
# You can change which AWS CLI Profile is used
AWS_PROFILE: "default"
networks:
credentials_network:
# This special IP address is recognized by the AWS SDKs and AWS CLI
ipv4_address: "169.254.170.2"
# Here we reference the application container that we are testing
# You can test multiple containers at a time, simply duplicate this section
# and customize it for each container, and give it a unique IP in 'credentials_network'.
app:
logging:
driver: awslogs
options:
awslogs-region: eu-west-3
awslogs-group: sharingmonsterlog
depends_on:
- ecs-local-endpoints
networks:
credentials_network:
ipv4_address: "169.254.170.3"
environment:
AWS_DEFAULT_REGION: "eu-west-3"
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI: "/creds"
我已使用 aws configure 命令将 AWS 凭证添加到我的 mac,并且凭证正确存储在 ~/.aws/credentials 中。
我正在使用 docker 2.2.0.4、docker-compose 1.25.4 和 docker-machine 0.16.2。
当我运行 docker-compose up 时,出现以下错误:
错误:刮板无法启动服务刮板:无法初始化日志记录驱动程序:NoCredentialProviders:链中没有有效的提供者。
已弃用。有关详细消息,请参阅 aws.Config.CredentialsChainVerboseErrors
错误:启动项目时遇到错误。
我相信这是因为我需要在 Docker 守护进程中设置 AWS 凭证,但我无法弄清楚这是如何在 macOS High Sierra 上完成的。
解决方案
我们需要将凭证传递给 Docker 守护进程。在基于 Systemd 的 Linux 上,由于 docker daemon 由 systemd 管理,我们需要为 docker daemon 设置 systemd 配置。
对于 mac,我们需要想办法在 Mac 中做类似的事情,并且需要了解 Mac docker daemon 是如何配置和启动的。
显然,Mac docker daemon 无法传递环境变量存在问题,因此会限制选项。发布问题的人最终以docker-cloudwatchlogs
stackoverflow 中提到了 Mac 上的几种方法。
但是,如果这是关于 docker compose,则可能有另一种方法可以使用 Docker Composer 功能通过环境变量传递 AWS 凭证。
或者在运行 docker compose 命令行时简单地设置环境变量。
AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY= ... AWS_SESSION_TOKEN= ... docker-compose up ...
请参阅Docker for Mac 也不能使用从文件加载的环境变量。
关于 AWS IAM 权限,请确保 AWS 凭证的 AWS 账户具有Docker 文档中指定的 IAM 权限。
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
推荐阅读
- c# - Xamarin 自定义 MarkupExtension 不适用于 Type 属性
- python - Python - 在网站上搜索最优惠的价格
- git - Bitbucket 预分支创建消息
- linux - 将所有环境变量传递给 sudo 脚本
- cypress - 如何在 Cypress 中查询 HTML 标签值?
- cakephp - CakeDC.users:更改新社交登录用户的默认角色
- java - 在 Android 中进行网络调用以响应 UI 事件
- tensorflow - InvalidArgumentError(参见上面的回溯):您必须为占位符张量提供一个值
- python - Selenium 网格在没有 chromedriver 本地安装的情况下无法工作
- python-3.x - 来自bash的多个python调用但没有加速