0

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 ??

Vishi
  • 21
  • 4
  • I'm wondering if the `types.ImageBuildOptions` 's Dockerfile represents a path to the Dockerfile. If it's a file path, I've been able to solve similar errors with an absolute path to the file, or relative path like `"./Dockerfile"` – gngchrs Nov 09 '17 at 16:51
  • Thank you for the quick response , actually i am very new to the goLang and even for the docker , i assume the Dockerfile attribute in the ImageBuildOptions is the path to the docker file and i have the Dockerfile in the same folder where my go programming is running. I tried with './Dockerfile' and also the abs path to the Dockerfile but with no success – Vishi Nov 09 '17 at 17:23
  • Possible you can get answer from https://stackoverflow.com/questions/38804313/build-docker-image-from-go-code. It's kind of limitation in SDK – sayboras Nov 10 '17 at 03:41

0 Answers0