MCPcopy Index your code
hub / github.com/cortexlabs/cortex / CopyFromContainer

Function CopyFromContainer

pkg/lib/docker/docker.go:284–306  ·  view source on GitHub ↗

The file or directory name of containerPath will be preserved in localDir For example, if the container has /aaa/zzz.txt, - CopyFromContainer(_, "/aaa", "~/test") will create "~/test/aaa/zzz.txt" - CopyFromContainer(_, "/aaa/zzz.txt", "~/test") will create "~/test/zzz.txt"

(containerID string, containerPath string, localDir string)

Source from the content-addressed store, hash-verified

282// - CopyFromContainer(_, "/aaa", "~/test") will create "~/test/aaa/zzz.txt"
283// - CopyFromContainer(_, "/aaa/zzz.txt", "~/test") will create "~/test/zzz.txt"
284func CopyFromContainer(containerID string, containerPath string, localDir string) error {
285 if !strings.HasPrefix(containerPath, "/") {
286 return errors.ErrorUnexpected("containerPath must start with /")
287 }
288
289 dockerClient, err := GetDockerClient()
290 if err != nil {
291 return err
292 }
293
294 reader, _, err := dockerClient.CopyFromContainer(context.Background(), containerID, containerPath)
295 if err != nil {
296 return WrapDockerError(err)
297 }
298 defer reader.Close()
299
300 _, err = archive.UntarReaderToDir(reader, localDir)
301 if err != nil {
302 return err
303 }
304
305 return nil
306}
307
308func EncodeAuthConfig(authConfig dockertypes.AuthConfig) (string, error) {
309 encoded, err := json.Marshal(authConfig)

Callers 1

runManagerFunction · 0.92

Calls 4

ErrorUnexpectedFunction · 0.92
UntarReaderToDirFunction · 0.92
GetDockerClientFunction · 0.85
WrapDockerErrorFunction · 0.85

Tested by

no test coverage detected