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

Function CopyToContainer

pkg/lib/docker/docker.go:251–278  ·  view source on GitHub ↗

The provided input will be extracted into the container's containerPath directory

(containerID string, input *archive.Input, containerPath string)

Source from the content-addressed store, hash-verified

249
250// The provided input will be extracted into the container's containerPath directory
251func CopyToContainer(containerID string, input *archive.Input, containerPath string) error {
252 if !strings.HasPrefix(containerPath, "/") {
253 return errors.ErrorUnexpected("containerPath must start with /")
254 }
255
256 dockerClient, err := GetDockerClient()
257 if err != nil {
258 return err
259 }
260
261 // this is necessary to ensure that missing parent directories are created in the container
262 input.AddPrefix = filepath.Join(containerPath, input.AddPrefix)
263
264 buf := new(bytes.Buffer)
265 _, err = archive.TarToWriter(input, buf)
266 if err != nil {
267 return err
268 }
269
270 err = dockerClient.CopyToContainer(context.Background(), containerID, "/", buf, dockertypes.CopyToContainerOptions{
271 AllowOverwriteDirWithFile: true,
272 })
273 if err != nil {
274 return WrapDockerError(err)
275 }
276
277 return nil
278}
279
280// The file or directory name of containerPath will be preserved in localDir
281// For example, if the container has /aaa/zzz.txt,

Callers 1

runManagerFunction · 0.92

Calls 4

ErrorUnexpectedFunction · 0.92
TarToWriterFunction · 0.92
GetDockerClientFunction · 0.85
WrapDockerErrorFunction · 0.85

Tested by

no test coverage detected