Add cp command to copy files out of containers, binary-safe
`portainer-cli cp <stack> <container>:<path> <dest>` goes through Docker's archive API, so unlike `console --run "cat …"` there's no TTY in between and binary files (database dumps) arrive intact. Works like `docker cp` for files and directories; a dest of "-" writes a single file to stdout. Stack and container lookup moves from Console into a shared Resolver module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+282
-100
No files matched your search
@@ -14,6 +14,7 @@ A Ruby command-line tool for interacting with [Portainer](https://www.portainer.
|
||||
- Supports both API key and JWT token authentication
|
||||
- Configurable SSL verification (useful for self-signed certificates)
|
||||
- `--run CMD` flag for running a specific command (e.g. `rails c`)
|
||||
- `cp` to copy files and directories out of containers, binary-safe
|
||||
- `--quiet` flag for scripting and AI agent use cases
|
||||
|
||||
## Requirements
|
||||
@@ -98,6 +99,16 @@ Suppresses all status output — only the container's own stdout/stderr is print
|
||||
portainer-cli console myapp --quiet --run "rails runner 'puts User.count'"
|
||||
```
|
||||
|
||||
### Copy files out of a container
|
||||
|
||||
Like `docker cp`, through Docker's archive API. There's no TTY in between, so binary files (database dumps, images) arrive intact — which `console --run "cat …"` can't promise.
|
||||
|
||||
```sh
|
||||
portainer-cli cp myapp backup:/backups/latest.dump ./latest.dump
|
||||
portainer-cli cp myapp app:/app/log ./ # directory → ./log
|
||||
portainer-cli cp myapp app:/etc/hostname - --quiet # single file to stdout
|
||||
```
|
||||
|
||||
### Create resources
|
||||
|
||||
```sh
|
||||
@@ -124,7 +135,7 @@ portainer-cli exec <endpoint-id> <container-name-or-id> --shell /bin/bash
|
||||
|
||||
## Container name resolution
|
||||
|
||||
When using `console`, names are resolved in this order:
|
||||
When using `console` or `cp`, names are resolved in this order:
|
||||
|
||||
1. **Exact match** — full container name or ID prefix
|
||||
2. **Compose pattern** — `<stack>-<service>-<N>` (e.g. `librarian` → `librarian-librarian-1`)
|
||||
|
||||