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

@simone-panicosimone-panico commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

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 dcantahFebruary 11, 2026 23:20
@jgloganjglogan added storage issues and features associated with storage. labels Feb 11, 2026
@jgloganjglogan modified the milestone: 2026-02Feb 11, 2026
Comment threadSources/ContainerCommands/Container/ContainerCopy.swift Outdated
Comment threadSources/Services/ContainerAPIService/Client/ContainerClient.swift Outdated
Comment threadSources/Services/ContainerAPIService/Client/ContainerClient.swift Outdated
Comment threaddocs/how-to.md Outdated
@JaewonHur

JaewonHur commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

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

JaewonHur commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

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 threadSources/ContainerCommands/Container/ContainerCopy.swift Outdated
Comment threadSources/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
Contributor

@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
ContributorAuthor

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

@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
ContributorAuthor

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 threadPackage.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
ContributorAuthor

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

github-actionsBot commented May 19, 2026

Copy link
Copy Markdown

Code Coverage

TierLine Coverage
Unit33.64%
Integration19.94%
Combined53.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:mainMay 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

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

jianliang00 pushed a commit to jianliang00/container that referenced this pull request Aug 28, 2026
…#1190)
## Type of Change
- [ ] Bug fix
- [x] New feature - [ ] Breaking change
- [x] Documentation update
## Motivation and Context
Adds the `container copy` (aliased as `cp`) command to copy files
between a running container and the local filesystem.
I saw [apple#1023](apple#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
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs
---------
Co-authored-by: jwhur <57657645+JaewonHur@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storageissues 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

@simone-panico@JaewonHur@dcantah@jglogan@vxnkjyffmq-code