https://pulumi.com logo
Title
b

better-park-50917

03/29/2023, 11:02 AM
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
src
-- myapp.api
----- Dockerfile
-- myapp.api.contracts
-- deploy (Pulumi c#)
----- Pulumi.yml
----- deploy.csproj
-- myapp.sln
c# 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

melodic-tomato-39005

03/29/2023, 3:35 PM
This is just a hunch, but did you try using
/
instead of
\\
? Forward-slashes work on Windows, too, and some tools expect them
b

better-park-50917

03/30/2023, 6:11 AM
I've changed the code as follows
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

fresh-spring-82225

04/03/2023, 8:00 PM
I’m also seeing a similar error on Windows. The same builder args work fine on MacOS.
What works for me on Windows:
build: {
  context: imageDir,
  dockerfile: `${imageDir}\\Dockerfile`
}
What doesn't work for me on Windows:
build: {
  context: imageDir
}
or
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
):
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
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