我的docker-compose文件:
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上是如何完成的。
答案 0 :(得分:1)
我们需要将凭据传递给Docker守护程序。在基于Systemd的Linux上,由于docker守护程序由systemd管理,因此我们需要为docker守护程序设置systemd配置。
对于Mac,我们需要找到一种在Mac中执行类似操作的方法,并且需要了解Mac docker守护程序是如何配置和启动的。
显然,Mac docker守护程序无法传递环境变量存在问题,因此将限制选项。该人发布的问题以docker-cloudwatchlogs
结尾在Mac上,stackoverflow中提到了几种方法。
但是,如果这与docker compose有关,则可能存在另一种使用Docker Composer功能通过环境变量传递AWS凭证的方法。
或者在运行docker compose命令行时简单地设置环境变量。
AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY= ... AWS_SESSION_TOKEN= ... docker-compose up ...
也请参阅Docker for Mac can't use loaded environment variable from file。
关于AWS IAM权限,请确保AWS凭证的AWS账户具有Docker document中指定的IAM权限。
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": "*"
}
]
}