Why "oc cp" operation fails when tar binary is absent in container ?

Solution In Progress - Updated -

Environment

  • Openshift Container Platform 3.x
  • Openshift Container Platform 4.x

Issue

  • oc cp operations require tar binary by default to execute the operation. But minimal and micro images do not have tar in it because of which oc cp can not be done in pods

Resolution

Root Cause

  • When oc cp is run, the files/directories that needs to be copied are compressed to form a tar ball
  • The tarball is then copied from the source container to the destination container(as mentioned in the command)
  • tarball in the destination container is now extracted
  • When this tar binary is absent is the container, compression and extraction fails
$ oc cp --help
Copy files and directories to and from containers.
Usage:
  oc cp <file-spec-src> <file-spec-dest> [flags]
Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'oc cp' will fail.

Diagnostic Steps

  • Spin a pod based on minimal image(or any image that misses tar binary) and try to perform oc cp
$ oc cp /tmp/hello pod:/tmp/
time="2023-11-27T15:55:56Z" level=error msg="exec failed: unable to start container process: exec: \"tar\": executable file not found in $PATH"
command terminated with exit code 255

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments