Currently, to get files into a container using the golang api I first must create the container and then use the CopyToContainer
function (Example Below).
Is it possible to create a container and specify files for it to have at create time, without having the files first on the file system?
Example 1)
func main() {
cli, err := client.NewEnvClient()
if err != nil {
panic(err)
}
resp, err := cli.ContainerCreate(context.Background(),
&container.Config{
Image: "alpine",
Cmd: []string{"ls", "/"},
}, nil, nil, "testContainer")
if err != nil {
panic(err)
}
fmt.Printf("Created: %v\n", resp.ID)
cli.CopyToContainer(context.Background(), resp.ID, "/", getTar(),types.CopyToContainerOptions{})
}
func getTar() io.Reader {
...
}
EDIT:
- Code spacing.