Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find Dockerfile as client on Windows #589

Closed
taraspos opened this issue Sep 29, 2016 · 9 comments
Closed

Can't find Dockerfile as client on Windows #589

taraspos opened this issue Sep 29, 2016 · 9 comments

Comments

@taraspos
Copy link
Contributor

taraspos commented Sep 29, 2016

Hello,
using client connecting to remote docker daemon.
When connecting from Linux to Docker daemon installed on CoreOS everything is ok.
When connecting from Windows to Docker daemon installed on CoreOS and trying to build docker image(on remote system) I get API error (500): {\"message\":\"Cannot locate specified Dockerfile: Dockerfile\"}. Pull images works ok.

err := client.BuildImage(docker.BuildImageOptions{
    Name: item.Name,
    // Dockerfile:     "Dockerfile",
    SuppressOutput: true,
    OutputStream:   &buf,
    RmTmpContainer: true,
    ContextDir:     filepath.Join(app.cnf.DockerfilesPath, item.Name),
})

where is: app.cnf.DockerfilesPath = "images" and item.Name = app1
Dockerfile is located in the: images/app1/Dockerfile

Building on remote docker daemon from client on Linux passes, and failing on Windows...

Any ideas why?

@fsouza
Copy link
Owner

fsouza commented Sep 29, 2016

@trane9991 try with path.Join instead of filepath.Join. This information is probably compared to the contents of the tarball sent to the remote server and tar always uses /, even on Windows.

@taraspos
Copy link
Contributor Author

taraspos commented Oct 1, 2016

@fsouza
Hello, I have found a problem. I created simple test application which creates Tar archives with use createTarStream method(https://github.com/fsouza/go-dockerclient/blob/master/tar.go#L20) and I found that problem is in the resolving relative path on Windows.
Example:
Creating 2 tar packages from the same directory, only one time with relative path and next time with absolute path:

func main() {
    path1 := `images`
    path2 := `bash`
    tarStr1, err := createTarStream(filepath.Join(path1, path2), "Dockerfile")
    fmt.Println(err)
    outFile1, err := os.Create(`test.tar`)
    // handle err
    defer outFile1.Close()
    _, err = io.Copy(outFile1, tarStr1)

    // ---------------------------

    path3 := `d:\Workspace\Git\go\src\test\images`
    path4 := `bash`
    tarStr2, err := createTarStream(filepath.Join(path3, path4), "Dockerfile")
    fmt.Println(err)
    outFile2, err := os.Create(`test2.tar`)
    // handle err
    defer outFile2.Close()
    _, err = io.Copy(outFile2, tarStr2)
}

checking results:

Conclusion:
Tar package created from directory with relative path is empty.

@taraspos
Copy link
Contributor Author

taraspos commented Oct 1, 2016

@fsouza
As a workaround adding absContextDir, err := filepath.Abs(filepath.Join(app.cnf.DockerfilesPath, item.Name)) works fine, but the issue need to be fixed in the library.

P.S. I tried to replace validateContextDirectory(https://github.com/fsouza/go-dockerclient/blob/master/tar.go#L67) with the builder.ValidateContextDirectory( https://github.com/fsouza/go-dockerclient/blob/master/tar.go#L67), but looks like issue persist. Need more testing.

@willseward
Copy link

@fsouza Does this bug still exist in the library? If so, you would be willing to implement the work-around that @trane9991 mentioned?

It would be nice to get https://github.com/dnephin/dobi working on Windows.

@ghost
Copy link

ghost commented Feb 6, 2018

This is also causing a problem in Harbur Captain on Windows. I have opened a bug there (harbur/captain#77) but it seems a fix here would be the correct solution.

@fsouza
Copy link
Owner

fsouza commented Feb 11, 2018

I apologize for leaving this bug hanging for so long. I just pushed a tentative fix. Unfortunately I don't have a Windows host where I can reproduce the bug nor test the fix, but the CI build did succeed: https://ci.appveyor.com/project/fsouza/go-dockerclient/build/355.

@jward-2ndwatch can you give it a shot?

@ghost
Copy link

ghost commented Feb 12, 2018

I will try to make some time and give it a shot soon. Thanks for getting to this.

@ghost
Copy link

ghost commented Feb 12, 2018

@fsouza I rebuilt Harbur Captain with this update and it looks like it solved the issue I was having. 👍

@fsouza
Copy link
Owner

fsouza commented Feb 12, 2018

@jward-2ndwatch thank you very much for confirming!

@fsouza fsouza closed this as completed Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants