【发布时间】:2021-02-06 02:50:40
【问题描述】:
我想使用 AWS CDK 在源代码中定义 CodeBuild 项目。 CodeBuild 项目需要能够构建然后推送 docker 镜像。
在 AWS 控制台中创建新的 CodeBuild 项目时,有一个选项:
Privileged 如果您想构建 Docker 映像或希望您的构建获得提升的权限,请启用此标志。
我没有在API Docs 中看到用于打开 Privileged 标志的等效 api。
var codeBuildProject = new Project(this, "Example_Build", new ProjectProps
{
ProjectName = "ExampleBuildFromCDK",
// How to add Privileged?
BuildSpec = BuildSpec.FromSourceFilename("example/buildspec.yml"),
Source = Source.CodeCommit(new CodeCommitSourceProps
{
Repository = Repository.FromRepositoryArn(this, "CodeCommit", CodeRepositoryArn),
BranchOrRef = "refs/heads/example/added-docker-images"
})
});
如果我尝试在不将 Privileged 设置为 true 的情况下运行我的构建,我会得到标准错误:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
如何使用 AWS CDK 创建具有“特权”的 CodeBuild 项目来构建 Docker 映像?
【问题讨论】:
标签: c# amazon-web-services aws-cdk aws-codebuild