Add container copy/cp command for host-container file transfer (#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 [#1023](https://github.com/apple/container/pull/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>
This commit is contained in:
Simone Panico
2026-05-20 10:03:36 -07:00
committed by GitHub
co-authored by jwhur
parent bd1916f9b3
commit 9895ba8d08
16 changed files with 754 additions and 4 deletions
+33
View File
@@ -465,6 +465,39 @@ container stats --no-stream web
container stats --format json --no-stream web
```
### `container copy (cp)`
Copies files between a container and the local filesystem. The container must be running. One of the source or destination must be a container reference in the form `container_id:path`.
**Usage**
```bash
container copy [--debug] <source> <destination>
```
**Arguments**
* `<source>`: Source path (local path or `container_id:path`)
* `<destination>`: Destination path (local path or `container_id:path`)
**Path Format**
* Local path: `/path/to/file` or `relative/path`
* Container path: `container_id:/path/in/container`
**Examples**
```bash
# copy a file from host to container
container cp ./config.json mycontainer:/etc/app/
# copy a file from container to host
container cp mycontainer:/var/log/app.log ./logs/
# copy using the full command name
container copy ./data.txt mycontainer:/tmp/
```
### `container prune`
Removes stopped containers to reclaim disk space. The command outputs the amount of space freed after deletion.