oc Cp Examples¶
Introduction¶
oc cp copies files between your workstation and a container. It depends on tar inside the container image, so minimal images may need a different approach.
When You Need This Command¶
Use this command when you need to inspect, change, or verify OpenShift resources from the terminal without relying on the web console.
Syntax¶
oc <command> <resource> [name] -n <project>
Practical Examples¶
oc cp ./config.yaml app/web-7c9d7f6f8b-jx4mk:/tmp/config.yaml -c web
oc exec pod/web-7c9d7f6f8b-jx4mk -n app -- ls -l /tmp/config.yaml
oc cp app/web-7c9d7f6f8b-jx4mk:/tmp/report.txt ./report.txt -c web
Example output:
-rw-r--r--. 1 1000690000 root 318 May 30 10:20 /tmp/config.yaml
Verification¶
oc get events -n app --sort-by=.lastTimestamp
oc get pods -n app -o wide
Common Mistakes¶
- Looking only at the final error and ignoring events.
- Checking the wrong project with oc.
- Changing several objects at once before confirming the current state.
Production Notes¶
Run read-only commands first, check the active project, and prefer declarative manifests for repeatable changes.
Quick Checklist¶
- Confirm the active project.
- Inspect the exact object named in the error.
- Read recent events.
- Apply one focused fix.
- Verify status after the change.
Related Guides¶
Summary¶
oc Cp Examples is most useful when paired with verification. Check the project, run the command against the intended object, and confirm the resulting OpenShift state.