-
-
Notifications
You must be signed in to change notification settings - Fork 287
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 create docker image for dotnet web api project #610
Comments
Your Docker image build fails. Run the Docker build via CLI, and check your |
@HofmeisterAn my dockerfile is generated from visual studio 2022, if I'm running docker build with -f flag and specifiy Dockerfile it works, there's a way your package can work with it? |
What's your |
In the root folder of the project |
@HofmeisterAn Okay so the problem is that You need to specify the solution path in the build, can I do this with ImageFromDockerfileBuilder? |
You need to set the path to the directory that contains the |
@HofmeisterAn there's a way to execute the following docker build command with ImageFromDockerfileBuilder: |
_ = new ImageFromDockerfileBuilder()
.WithName("authorizationserver.webapiapplication")
.WithDockerfileDirectory("C:/Repos/Microservices/Applications/AuthorizationServer/Application/WebApiApplication")
.Build(); This will create a tarball of the content of |
I currently have the same problem. After quite a bit of debugging, I found that trailing For me, after fixing that it still fails to build the image. Does In my case, my Dockerfile lives at await new ImageFromDockerfileBuilder()
.WithName(BaseImage)
.WithDockerfile(Path.Combine("common", "dotnet", "Dockerfile"))
.WithDockerfileDirectory(CommonDirectoryPath.GetGitDirectory(), "src")
.Build() I feel like this issue would be pretty easy to solve if there was any inkling of an error message. I tried debugging into the internal Docker.Dotnet calls to see if I could pull anything from the log steam it seems to be using, but either my debugging skills are lacking or there's nothing there. I also tried setting up an XUnit |
That is fixed with #604.
Testcontainters for .NET creates a tarball of the content of Your configuration above looks good. The
Docker.Dotnet does not forward the error. The issue has been fixed recently with dotnet/Docker.DotNet#590, but there is no new release yet. But I agree, we need to improve the developer experience here, it looks like the current implementation or behavior is too complicated. Does that help? |
@Omrisha have you been able to solve the issue? Do you need more help? |
I was able to figure out how to get logs from Docker.Dotnet, no idea why it wasn't working before but the internal Nice to see there may be better error messages coming in the future. I only skimmed the logging code, but at least at a high level it seems to be all wired up via the @Omrisha Not sure if this will help you but this is the loop I stepped through to find the issue in |
Alright best I can tell, my The logging was because I wasn't setting the logger early enough in the process. I was building the image in a fixture, but trying to use |
That is usually the case. If I have issues I look straight into the tarball. OC, that is not convenient. What about adding the logger to testcontainers-dotnet/src/Testcontainers/Images/DockerfileArchive.cs Lines 77 to 90 in 1ce11d3
Indeed, that looks wrong, it is similar to #604. The testcontainers-dotnet/src/Testcontainers/Images/IgnoreFile.cs Lines 66 to 70 in 1ce11d3
It generates an ignore pattern for |
@HofmeisterAn I still can't build docker image with your library, I have multiple project in the solution so i can't have my docker file in the solution folder. |
You do it already with |
…dockerignore entry ends with /*
Got pretty the same problem Can't build docker image from the docker file
Using the code from your repo example Dockerfile lives in the solution folder |
Usually, the Docker build fails. You can attach a logger, then you will see which part fails (it will contain the Docker build output). Something like will do it: static WeatherForecastImage()
{
TestcontainersSettings.Logger = new MyLogger();
}
public sealed class MyLogger : ILogger, IDisposable
{
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
File.AppendAllText("diagnostic.log", formatter.Invoke(state, exception));
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public IDisposable BeginScope<TState>(TState state)
{
return this;
}
public void Dispose()
{
}
} |
@HofmeisterAn thanks for the answer. I tried to copy dockerignore file from your weather src. Looks like it changed the error. Don't know what exactly in my dockerignore makes the logic fail. Will investigate new error more, thanks |
I read the doc and didn't understand from it that |
Hm, I do not know how to explain it more explicit. If you look into the example, the build context (
|
I'm trying to use the dockerfile create by visualstudio located at
So what param must I use, I thinks a made mistake here. |
Builder configuration_ = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory("C:/GitHub-Issue-610")
.WithDockerfile("src/WeatherForecastDockerfile")
.Build(); WeatherForecastDockerfileFROM alpine:3.14
COPY src/foo.txt /tmp/ |
I made a little typo mistake
Builder configuration_ = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory("C:/Users/andre.hofmeister/Desktop/GitHub-Issue-610")
.WithDockerfile("src/WeatherForecast/Dockerfile")
.Build(); WeatherForecastDockerfileFROM alpine:3.14
COPY src/foo.txt /tmp/ |
Yes: GitHub-Issue-610.zip. |
…se, it cuts the first character of the relative path)
With what you give me, I get this error : |
Then you are doing something wrong. Attach a logger or debug into it. |
I use the your example a little reworked for it to be stand alone.
|
Use forward slashes. We will normalize the path in the next version automatically. The following diff runs on my machine: diff --git a/src/WeatherForecast/Dockerfile b/src/WeatherForecast/Dockerfile
index c8e80ff..733edf1 100644
--- a/src/WeatherForecast/Dockerfile
+++ b/src/WeatherForecast/Dockerfile
@@ -1,2 +1,26 @@
-FROM alpine:3.14
-COPY src/foo.txt /tmp/
+#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
+
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
+WORKDIR /app
+EXPOSE 80
+EXPOSE 443
+
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
+WORKDIR /src
+COPY ["src/WeatherForecast/WeatherForecast.csproj", "src/WeatherForecast/"]
+COPY ["src/WeatherForecast.Contexts/WeatherForecast.Contexts.csproj", "src/WeatherForecast.Contexts/"]
+COPY ["src/WeatherForecast.Repositories/WeatherForecast.Repositories.csproj", "src/WeatherForecast.Repositories/"]
+COPY ["src/WeatherForecast.Entities/WeatherForecast.Entities.csproj", "src/WeatherForecast.Entities/"]
+COPY ["src/WeatherForecast.Interactors/WeatherForecast.Interactors.csproj", "src/WeatherForecast.Interactors/"]
+RUN dotnet restore "src/WeatherForecast/WeatherForecast.csproj"
+COPY . .
+WORKDIR "/src/src/WeatherForecast"
+RUN dotnet build "WeatherForecast.csproj" -c Release -o /app/build
+
+FROM build AS publish
+RUN dotnet publish "WeatherForecast.csproj" -c Release -o /app/publish /p:UseAppHost=false
+
+FROM base AS final
+WORKDIR /app
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "WeatherForecast.dll"]
diff --git a/tests/WeatherForecast.Test/WeatherForecastImage.cs b/tests/WeatherForecast.Test/WeatherForecastImage.cs
index 103f8d7..c2676fa 100644
--- a/tests/WeatherForecast.Test/WeatherForecastImage.cs
+++ b/tests/WeatherForecast.Test/WeatherForecastImage.cs
@@ -32,7 +32,7 @@ public sealed class WeatherForecastImage : IDockerImage, IAsyncLifetime
_ = await new ImageFromDockerfileBuilder()
.WithName(this)
.WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), string.Empty)
- .WithDockerfile("src\\WeatherForecast\\Dockerfile")
+ .WithDockerfile("src/WeatherForecast/Dockerfile")
.WithBuildArgument("RESOURCE_REAPER_SESSION_ID", ResourceReaper.DefaultSessionId.ToString("D")) // https://github.com/testcontainers/testcontainers-dotnet/issues/602.
.WithDeleteIfExists(false)
.Build() |
I have effectively not may enough attention on the path you give me, my mistake. |
…se, it cuts the first character of the relative path), Normalize paths to forward slashes (#651)
I will close this issue, because it contains all kinds of information to set up the configuration properly. @Omrisha this might be interesting for you as well: #610 (comment). Depending on your Dockerfile this might work: _ = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory("C:/Repos/Microservices")
.WithDockerfile("Applications/AuthorizationServer/Application/WebApiApplication/Dockerfile")
.Build(); Thanks to everyone. Due to your various configurations, we were able to add some more improvements to the builder. Version 2.2.0 as well as the next release are not that strict anymore regarding path conventions etc. If you still struggle, to set it up, please do not hesitate to reopen the issue again. |
I again struggle to set up an image. My setup is quite similar to your example.
So if I'm correct I need to use But I have the {"Docker image has not been created."} I have used a logger to see what append but it seams the problem is in my path, because he gives me only this:
If you can tell me where I'm wrong it will help me a lot. |
You exclude your own Dockerfile. |
Thanks you save me :) |
Describe the bug
I have Web API .NET 6 project with docker file in it, when I try creating docker file using ImageFromDockerFileBuilder it failed with not incomprehensible probelm:
"System.AggregateException: 'One or more errors occurred. (Docker image verte.authorizationserver.webapiapplication:1665577986 has not been created.)'"
It's does not give more errors so I can't know what is wrong.
To Reproduce
Steps to reproduce the behavior:
IDockerImage image = await new ImageFromDockerfileBuilder() .WithName(this) .WithDockerfileDirectory("C:\\Repos\\verte.Microservices\\Applications\\AuthorizationServer\\Application\\Verte.AuthorizationServer.WebApiApplication") .WithDockerfile("Dockerfile") .WithBuildArgument("RESOURCE_REAPER_SESSION_ID", ResourceReaper.DefaultSessionId.ToString("D")) .WithDeleteIfExists(false) .Build() .ConfigureAwait(false);
Expected behavior
Dockerfile should be created, also my dockerfile is working just fine with docker compose and docker CLI.
Screenshots
The text was updated successfully, but these errors were encountered: