Skip to content

Add container copy/cp command for host-container file transfer#1190

Merged
JaewonHur merged 31 commits into
apple:mainfrom
simone-panico:main
May 20, 2026
Merged

Add container copy/cp command for host-container file transfer#1190
JaewonHur merged 31 commits into
apple:mainfrom
simone-panico:main

Conversation

@simone-panico
Copy link
Copy Markdown
Contributor

@simone-panico simone-panico commented Feb 10, 2026

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes #232.

Adds the container copy (aliased as cp) command to copy files between a running container and the local filesystem.

I saw #1023 and the feedback from @dcantah — the previous attempt relied on tar being installed inside the container.
This implementation takes the recommended approach:
file transfers go through the guest agent via the existing copyIn/copyOut methods on the core Containerization, with no dependency on container tooling.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@simone-panico simone-panico marked this pull request as ready for review February 10, 2026 21:22
@JaewonHur
Copy link
Copy Markdown
Contributor

Related to #232

@jglogan jglogan requested a review from dcantah February 11, 2026 23:20
@jglogan jglogan added storage issues and features associated with storage. labels Feb 11, 2026
@jglogan jglogan requested review from JaewonHur February 11, 2026 23:21
@jglogan jglogan modified the milestone: 2026-02 Feb 11, 2026
Comment thread Sources/ContainerCommands/Container/ContainerCopy.swift Outdated
Comment thread Sources/Services/ContainerAPIService/Client/ContainerClient.swift Outdated
Comment thread Sources/Services/ContainerAPIService/Client/ContainerClient.swift Outdated
Comment thread docs/how-to.md Outdated
Comment thread Sources/Services/ContainerSandboxService/Client/SandboxClient.swift
@JaewonHur
Copy link
Copy Markdown
Contributor

JaewonHur commented Feb 17, 2026

CopyOut/CopyIn Scenarios: Current vs Docker Behavior

Scenario 1: copy(in/out) src dst (src must exist)

  • File, Directory → Non-existing:

    • Docker (desired): save as dst
    • Current: File is saved as dst, Directory is not supported.
  • File → File

    • Docker (desired): replace dst
    • Current: replace dst
  • Directory → File

    • Docker (desired): error
    • Current: Directory is not supported
  • File, Directory → Directory

    • Docker (desired): save under dst
    • Current: File returns error, Directory is not supported.

Scenario 2: copy(in/out) src dst/ (dst must be a directory if existing)

  • File → Non-existing:

    • Docker (desired): error no such directory
    • Current: dst is created and src file is saved under dst.
  • Directory → Non-existing:

    • Docker (desired): save as dst
    • Current: Directory is not supported.
  • File, Directory → Directory

    • Docker (desired): save under dst
    • Current: File is saved under dst. Directory is not supported.

Scenario 3: copy(in/out) src/ dst (src must be an existing directory)

  • Directory → Non-existing:

    • Docker (desired): save as dst
    • Current: Directory is not supported.
  • Directory → File

    • Docker (desired): error
    • Current: Directory is not supported.
  • Directory → Directory

    • Docker (desired): save under dst
    • Current: Directory is not supported.

Scenario 4: copy(in/out) src/ dst/ (src must be an existing directory & dst must be a directory if existing)

  • Directory → Non-existing:

    • Docker (desired): save as dst
    • Current: Directory is not supported.
  • Directory → Directory

    • Docker (desired): save under dst
    • Current: Directory is not supported.

@JaewonHur
Copy link
Copy Markdown
Contributor

JaewonHur commented Feb 18, 2026

Hi @simone-panico
Above I summarized the desired behavior and current behavior.

The bold italic phrases are what is different from desired behavior (i.e., docker) now, and can be addressed.

Below is general comments.

  1. Copying directory is not supported yet, we need to handle it later.
  2. If dst/, it would be better to check in command line if dst is directory if it exists.

Comment thread Sources/ContainerCommands/Container/ContainerCopy.swift Outdated
Comment thread Sources/ContainerCommands/Container/ContainerCopy.swift
@JaewonHur
Copy link
Copy Markdown
Contributor

Hi @simone-panico
Could you try this PR with apple/containerization#474, which supports copying directories.

You may need to build this project with local containerization (BUILDING.md), and wire up SandboxService.

@dcantah
Copy link
Copy Markdown
Member

dcantah commented Feb 19, 2026

@JaewonHur the change above does not allow copying directories. It adds a tar reader/writer that will be used to support this, but it's not in the change itself.

@simone-panico
Copy link
Copy Markdown
Contributor Author

If you’re interested, I could try to create a Directory Copier within containerization. It would also be a great challenge for me

@simone-panico
Copy link
Copy Markdown
Contributor Author

Hey @JaewonHur
No worries, and thank you for the Stat RPC. I've started looking into it but haven't finished yet. I'll get to it as soon as I can 😄

@JaewonHur
Copy link
Copy Markdown
Contributor

@simone-panico Thank you!
You might want to change copyIn and copyOut methods of LinuxContianer in containerization to use stat RPC.

@simone-panico
Copy link
Copy Markdown
Contributor Author

Hey @JaewonHur, sorry this took so long. I had to finish my finals.
I’ve now implemented the Stat RPC in apple/containerization#727 and updated this PR to use it for copyIn.
Every copy test is passing now: 70/70. 😄

@JaewonHur
Copy link
Copy Markdown
Contributor

@simone-panico Not at all :) I really appreciate for all your hard work!

Comment thread Package.swift Outdated
@JaewonHur
Copy link
Copy Markdown
Contributor

@simone-panico Could you do make fmt and push again.

Once the containerization PR is merged, we should bump that in Package.swift, and able to merge this PR.

@simone-panico
Copy link
Copy Markdown
Contributor Author

This one also doesn't seem to be signed correctly. Could you please sign this as well?

Should be correct now, right?

@JaewonHur
Copy link
Copy Markdown
Contributor

Yes. Looks good.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Code Coverage

Tier Line Coverage
Unit 33.64%
Integration 19.94%
Combined 53.01%

JaewonHur pushed a commit to apple/containerization that referenced this pull request May 19, 2026
This pull request enhances the handling of file and directory copy
operations in Linux containers, particularly by improving destination
path resolution and error handling for the `copyIn` operation with the
`Stat RPC`

This PR is needed for
[container#1190](apple/container#1190)
@JaewonHur
Copy link
Copy Markdown
Contributor

Hi! I tagged latest containerization to 0.32.2.

Here could you update scVersion in Package.swift to 0.32.2, then swift package update containerization?

The Package.resolved file should have only the containerization package updated (and the originHash at the top).

@JaewonHur JaewonHur merged commit 9895ba8 into apple:main May 20, 2026
3 checks passed
@JaewonHur
Copy link
Copy Markdown
Contributor

@simone-panico Finally merged :) Thank you so much for your hard work and patience!

@jglogan
Copy link
Copy Markdown
Contributor

jglogan commented May 20, 2026

@simone-panico Definitely, thanks for the patience and the effort you've put in. It's nice to have this feature in place!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage issues and features associated with storage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: Add container cp command to copy files into and out of running containers

5 participants