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

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

Open
Marvin-Brouwer opened this issue Feb 24, 2023 · 4 comments
Open

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

Marvin-Brouwer opened this issue Feb 24, 2023 · 4 comments

Comments

@Marvin-Brouwer
Copy link

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
Copy link
Author

Marvin-Brouwer commented Feb 24, 2023

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
Copy link
Author

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
Copy link
Owner

neat, youre more than welcome to do a PR!

Cheers,
Mario :)

@Marvin-Brouwer
Copy link
Author

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

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

2 participants