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)
| 282 | // - CopyFromContainer(_, "/aaa", "~/test") will create "~/test/aaa/zzz.txt" |
| 283 | // - CopyFromContainer(_, "/aaa/zzz.txt", "~/test") will create "~/test/zzz.txt" |
| 284 | func 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 | |
| 308 | func EncodeAuthConfig(authConfig dockertypes.AuthConfig) (string, error) { |
| 309 | encoded, err := json.Marshal(authConfig) |
no test coverage detected