无法通过 Spotify Docker 客户端将文件复制到 Docker 容器

Cannot copy file to Docker container via Spotify Docker Client

我想通过 Docker 客户端通过 Spotify -

将文件复制到非 运行ning 容器

文件创建方式如下 -

File.createTempFile("olb-", "-temp").deleteOnExit().writeText("some text")

当我尝试时:

client.copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/asd.json")

我得到:

Either container 1adbf9c1ee511272bec78a46be08bf9299c317b11cdb176eed986640ac86a38c or path /app/my_json.json not found.

嗯,好的 - 我在使用 RUN touch /app/my_json.json 构建图像时创建了这个文件 下一个 运行:

client.copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/my_json.json")

结果是

{"message":"extraction point is not a directory"}

好的...我尝试了目录

copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/")

结果:

{"message":"Error processing tar file(exit status 1): cannot overwrite directory \"/\" with non-directory \"/\""}

"/app"

也一样

知道如何通过 Java 客户端将文件复制到 docker 容器吗?

事实证明,我必须创建全新的文件夹,然后在其中创建单个文件并复制该文件夹。

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")