mariotoffia / FluentDocker

Use docker, docker-compose local and remote in tests and your .NET core/full framework apps via a FluentAPI
Apache License 2.0
1.31k stars 97 forks source link

`Copy` and `Add` don't work as expected. #284

Open Marvin-Brouwer opened 1 year ago

Marvin-Brouwer commented 1 year ago

I'm trying to build my own image, and I want to copy some files onto it. When I use an absolute path, the COPY and ADD commands break. When I try to generate the path and set copy the files there first, the ${RND} part of the template don't match.

I'm currently trying this:


        var tempDir = (TemplateString)@"${TEMP}/fluentdockertest/${RND}";
        Directory.CreateDirectory(tempDir);
        var initScriptPath = (TemplateString)@$"{tempDir}/{InitScriptName}";
        CopyInitScript(initScriptPath, dbCreateScripts);

        var imageName = $"{container.FriendlyApplicationName}/{options.Name}";
        container
            .Builder
            .DefineImage(imageName).ReuseIfAlreadyExists()
            .From("mcr.microsoft.com/mssql/server:2022-latest", "base")
            .UseWorkDir("/")
            .Add(InitScriptName, $"startup/")
            .ExposePorts(1433);

The CopyInitScript is incorrectly named, it generates a script at runtime. How do I get the correct temp folder so my dockerfile and resources can be placed next to each other?

Marvin-Brouwer commented 1 year ago

Some additional context. I tried doing

.Add($"../{InitDbScriptName}", $"startup/")

Of course without the random folder in tempDir but then it can't find the file

And then the generated dockerfile looks like this:

FROM mcr.microsoft.com/mssql/server:2022-latest AS base
WORKDIR /
ADD  startup/
EXPOSE 1433
Marvin-Brouwer commented 1 year ago

Ok, I figured this one out, there's a method to set the working directory, which I thought was the same as setting the working directory of the dockerfile. I would like to have some more documentation on how to use Copy and Add. Maybe CSDOC would suffice, then you can also reference the correct workdir method

mariotoffia commented 1 year ago

neat, youre more than welcome to do a PR!

Cheers, Mario :)

Marvin-Brouwer commented 1 year ago

I might at some point. However, I put the project where I'm using this on pause and I'm not the biggest docker wizard so I'll need to review that project to add to yours at some point. So not making any promises