You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Request]: Add container cp command to copy files into and out of running containers #232
It's possible to work around the lack of cp by execing tar in the container image and piping the output to tar on the host, however this isn't a general solution because the container might not have a tar binary.
Code of Conduct
I agree to follow this project's Code of Conduct
Reacted by Danny Canter, Ali Riayde Jawad, Shadab Mohammad, Alex N, WingDust, Kohei Ota (inductor), Michael Bolin, Geoffrey Goetz, Spongebob, Falk Woldmann Lu and 1 more
Update on this: I started the work here. The overall design we were going for was to create a tar file of the requested content either on the host or container side depending on the direction requested, then send that via the vminit GRPC client and untar on the receiving side.
Since swift does not have any native libraries for dealing with tar files, we looked into using our ContainerizationArchive library instead. However, it looks like the swift linux SDK does not include libarchive (and some others) today, which we would need for using ContainerizationArchive for the vminitd side of the code since that runs in the linux guest.
One option would be for us to make our own tar swift library for use. Another option is to manually pull in the libarchive library to the linux SDK root when we build (I would like to avoid this unless absolutely necessary). I'd love to hear if others have alternative suggestions!
Here's the exact list of libraries we're missing when building vminitd with swift linux SDK
[1/1] Planning build
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
ld.lld: error: unable to find library -lbz2
ld.lld: error: unable to find library -llzma
ld.lld: error: unable to find library -larchive
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[129/131] Linking vminitd
My containerization branch is here in case anyone is curious. However, the code was not done and the branch is still in a bad shape so keep that in mind 😅
One of the more common scenarios I have used the 'docker cp' for in the past was to copy an initialization script to a database container like the following:
It is very convenient in such cases to be able to copy the init.cql file over and over to reset the database. This way I do not have to rebuild the container, or stop, delete and run a fresh image of a pre-built all the time. I have also noticed that the "docker cp" command is able to create directories (and sub directories) inside the container even if they are not there in the first place.
I see this issue is labeled next so the team plans to ship it. If there's room for an external contribution while you're busy with other work this month (per @jglogan's note on #1463), I'd like to scope a cp implementation that follows the ContainerExport pattern.
Sketch of the approach:
New Sources/ContainerCommands/Container/ContainerCp.swift as a built-in subcommand under the existing Container group in Application.swift. Symmetric with Export/Exec rather than a plugin, since every other lifecycle command is built-in.
Two positional arguments parsed as Docker does: detect : to determine direction. Both host → container and container → host modes, plus - for stdin/stdout streaming so callers like Swift SDK Generator (cited in the issue) can pipe directly.
-L / --follow-link flag matching Docker's default-no-follow behavior.
Container → host reuses the tar archive path that ContainerExport already produces; host → container needs a new import(id:archive:targetPath:) on the API server unless one already exists.
Tests under Tests/CLITests/Subcommands/Cp/ modeled on TestCLIRunLifecycle.swift.
Two questions before I open a PR:
Is there an internal design doc or in-flight branch I should be aware of so this doesn't conflict?
If host → container and container → host don't both fit cleanly in one PR, would you prefer to split (start with host → container) or ship together?
Activity
katiewasnothere commentedon Jul 11, 2025
Update on this: I started the work here. The overall design we were going for was to create a tar file of the requested content either on the host or container side depending on the direction requested, then send that via the vminit GRPC client and untar on the receiving side.
Since swift does not have any native libraries for dealing with tar files, we looked into using our ContainerizationArchive library instead. However, it looks like the swift linux SDK does not include libarchive (and some others) today, which we would need for using ContainerizationArchive for the vminitd side of the code since that runs in the linux guest.
One option would be for us to make our own tar swift library for use. Another option is to manually pull in the libarchive library to the linux SDK root when we build (I would like to avoid this unless absolutely necessary). I'd love to hear if others have alternative suggestions!
katiewasnothere commentedon Jul 11, 2025
Here's the exact list of libraries we're missing when building vminitd with swift linux SDK
My containerization branch is here in case anyone is curious. However, the code was not done and the branch is still in a bad shape so keep that in mind 😅
gleison commentedon Jul 17, 2025
Hi!
There is a workaround to copy a file to container?
I tried something like that:
container exec -i container_id sh -c 'cat > ./file' < ./filebut i get a error:
container/RunCommand.swift:223: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={NSUnderlyingError=0x600000390630 {Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"}}katiewasnothere commentedon Jul 17, 2025
Hi @gleison you could try adding a virtiofs mount to your container and copying your files into that. Would that work for your scenario?
ggeoffre commentedon Sep 21, 2025
One of the more common scenarios I have used the 'docker cp' for in the past was to copy an initialization script to a database container like the following:
It is very convenient in such cases to be able to copy the init.cql file over and over to reset the database. This way I do not have to rebuild the container, or stop, delete and run a fresh image of a pre-built all the time. I have also noticed that the "docker cp" command is able to create directories (and sub directories) inside the container even if they are not there in the first place.
mvanhorn commentedon Apr 30, 2026
I see this issue is labeled
nextso the team plans to ship it. If there's room for an external contribution while you're busy with other work this month (per @jglogan's note on #1463), I'd like to scope acpimplementation that follows theContainerExportpattern.Sketch of the approach:
Sources/ContainerCommands/Container/ContainerCp.swiftas a built-in subcommand under the existingContainergroup inApplication.swift. Symmetric withExport/Execrather than a plugin, since every other lifecycle command is built-in.:to determine direction. Bothhost → containerandcontainer → hostmodes, plus-for stdin/stdout streaming so callers like Swift SDK Generator (cited in the issue) can pipe directly.-L/--follow-linkflag matching Docker's default-no-follow behavior.ContainerExportalready produces; host → container needs a newimport(id:archive:targetPath:)on the API server unless one already exists.Tests/CLITests/Subcommands/Cp/modeled onTestCLIRunLifecycle.swift.Two questions before I open a PR:
JaewonHur commentedon Apr 30, 2026
@mvanhorn Hi! We have a PR working on it #1190. Sorry for delay! I really hope this PR merged soon.
jglogan commentedon May 21, 2026
Closed by #1190.