Hi, I'm trying to build a docker image but I get t...
# general
b
Hi, I'm trying to build a docker image but I get the following error:
error: failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount1744191223/myapp.api\Dockerfile: no such file or directory
folder structure
Copy code
src
-- myapp.api
----- Dockerfile
-- myapp.api.contracts
-- deploy (Pulumi c#)
----- Pulumi.yml
----- deploy.csproj
-- myapp.sln
c# code
Copy code
var apiImage = new Image("api-image", new()
{
   Build = new DockerBuildArgs
   {
      Context = "..",
      Dockerfile = "..\\myapp.api\\Dockerfile",
      Platform = "linux/amd64",
   },
   ImageName = repo.RepositoryUrl,
   Registry = new RegistryArgs
   {
      Server = repo.RepositoryUrl,
      Username = username,
      Password = password
   }
});
Any suggestions what's wrong? I'm using Windows machine (powershell)
m
This is just a hunch, but did you try using
/
instead of
\\
? Forward-slashes work on Windows, too, and some tools expect them
b
I've changed the code as follows
Copy code
var apiImage = new Image("api-image", new()
{
   Build = new DockerBuildArgs
   {
      Context = "..",
      Dockerfile = "../myapp.api/Dockerfile",
      Platform = "linux/amd64",
   },
   ImageName = repo.RepositoryUrl,
   Registry = new RegistryArgs
   {
      Server = repo.RepositoryUrl,
      Username = username,
      Password = password
   }
});
and got error
error: error hashing dockerfile "../myapp.api/Dockerfile": could not open file ../myapp.api/Dockerfile: open ..\..\myapp.api\Dockerfile: The system cannot find the path specified.
f
I’m also seeing a similar error on Windows. The same builder args work fine on MacOS.
What works for me on Windows:
Copy code
build: {
  context: imageDir,
  dockerfile: `${imageDir}\\Dockerfile`
}
What doesn't work for me on Windows:
Copy code
build: {
  context: imageDir
}
or
Copy code
build: {
  context: imageDir,
  dockerfile: `${imageDir}/Dockerfile`
}
okay, I figured it out. This one was a little weird.
buildImage.ts
I'm calling the function
buildImage
twice, in order to tag the image with both
latest
and a hash. When I call
buildImage
the 2nd time, fails with this error (where
imageDir
is
test-image
):
Copy code
error: error hashing dockerfile "test-image/Dockerfile": could not open file test-image/Dockerfile: open test-image\test-image\Dockerfile: The system cannot find the path specified.
This only happens on Windows. I can fix it on windows by adding
Copy code
dockerfile:`${imageDir}\\Dockerfile`
but if I use
${_imageDir_}/Dockerfile
it doesn't work on Windows -- it works fine on Mac OS.
Confirmed that this is a regression in @pulumi/docker 4.x from 3.x
Workaround is to convert
imageDir
to an absolute path
Filed a bug for this regression in @pulumi/docker: https://github.com/pulumi/pulumi-docker/issues/578