dshmkgq558192365 2017-11-09 15:49
浏览 32

无法在golang中建立docker映像

I am executing this test case inside a container as the golang:1.7 is not available on my host machine. I created a container and start it in bash mode and followed the steps mentioned in the link https://tdeheurles.github.io/acting-on-docker-from-inside-docker/

And here is the problem I am facing, when I am trying to build a docker image , it is showing following error always

Error response from daemon: Cannot locate specified Dockerfile: Dockerfile

Here is the my Dockerfile content

FROM golang:1.9  

I created this Dockerfile just for testing to make sure I can able to creating the image with the golang program.

Here is my goLang logic

dockerFile := "Dockerfile"
imageName := "test_build_image"

ctx := context.Background()

cli, err := client.NewEnvClient()

buildOptions := types.ImageBuildOptions{ Tags: []string{imageName}, Dockerfile: dockerFile }

buildResponse, err := cli.ImageBuild(ctx,dockerBuildContext, buildOptions)

EDIT:1

Strangely this piece of code is working

cli, _ := client.NewEnvClient()
    dockerBuildContext, err := os.Open("anil_test.tar")
    defer dockerBuildContext.Close()

    buildOptions := types.ImageBuildOptions{Tags: []string{"my_image"}, Dockerfile: "Dockerfile"}

    buildResponse, err := cli.ImageBuild(context.Background(), dockerBuildContext, buildOptions)

When I am using same piece of code by passing my Dockerfile as an argument to the os.Open("Dockerfile") it is not working .Does it mean we need to pass only .tar file of Docker ??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大