电商公司名称怎么起名关键词优化搜索引擎
目前docker支持以下几种方式指定上下文来构建镜像
- 本地项目路径(如:/tmp/xxx)
- 本地压缩包路径(如:/tmp/xxx.tar)
- docekrfile文本链接(如:https://x.com/xxx/dockerfile)
- 压缩包文件链接(如:https://x.com/xxx.tar)
- git仓库链接(如:https://x.com/xxx.git)
以上几种都可以使用golang代码实现
在此记录下使用git仓库链接构建构建的步骤
import ("context""github.com/docker/docker/api/types""github.com/docker/docker/client"
)func main() {cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())if err != nil {panic(err)}// 1.公开的项目地址// 格式:https://github.com/[组名|用户名]/[项目名].git#[分支名]// 如:https://github.com/qf0129/project-a.git#master// 2.私有的项目地址,使用ssh密钥,已将当前主机公钥添加到git后台// 格式:https://github.com/[GROUP]/[PROJECT_NAME].git#[BRANCH]// 如:https://github.com/qf0129/project-b.git#master// 3.私有的项目地址,使用Token,在git后台申请// 格式:https://[USER]:[TOKEN]@github.com/[GROUP]/[PROJECT_NAME].git#[BRANCH]// 如:https://qf0129:xxxxx@github.com/qf0129/project-b.git#mastergitUrl := "https://github.com/qf0129/project-a.git#master"// 开始构建resp, err := cli.ImageBuild(context.TODO(), nil, types.ImageBuildOptions{RemoteContext: gitUrl})if err != nil {panic(err)}
}
参考 https://docs.docker.com/build/building/context/#what-is-a-build-context