I want to copy file to the not running container via Docker Client by Spotify -
File is created like -
File.createTempFile("olb-", "-temp").deleteOnExit().writeText("some text")
When I try:
client.copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/asd.json")
I get:
Either container 1adbf9c1ee511272bec78a46be08bf9299c317b11cdb176eed986640ac86a38c or path /app/my_json.json not found.
Well, ok - I create this file while building image with RUN touch /app/my_json.json
Next run:
client.copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/my_json.json")
Resulted in
{"message":"extraction point is not a directory"}
Ok... I tried directory
copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/")
Result:
{"message":"Error processing tar file(exit status 1): cannot overwrite directory \"/\" with non-directory \"/\""}
Same for "/app"
Any ideas how to copy file into docker container via Java client?
It turned out that I must create whole new folder, then single file in it and copy that folder.
val dir = Files.createTempDirectory("tem-folder-")
Files.createFile(dir.resolve("filename")).toFile().writeText("data to write")
val toBeCopied = dir.toFile()
cliend.copyToContainer(toBeCopied.toPath(), "containerId", "targetPath")