mirror of
https://github.com/apple/container.git
synced 2026-09-27 17:36:08 -04:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user