| 67 | } |
| 68 | |
| 69 | func (d Docker) Import(ctx context.Context, file string, image string) (string, error) { |
| 70 | f, err := os.Open(file) |
| 71 | defer f.Close() |
| 72 | if err != nil { |
| 73 | return "", err |
| 74 | } |
| 75 | |
| 76 | reader, err := d.client.ImageImport(ctx, types.ImageImportSource{Source: f, SourceName: "-"}, image, types.ImageImportOptions{}) |
| 77 | if err != nil { |
| 78 | return "", err |
| 79 | } |
| 80 | buf := new(bytes.Buffer) |
| 81 | _, _ = buf.ReadFrom(reader) |
| 82 | return buf.String(), nil |
| 83 | } |
| 84 | |
| 85 | func (d Docker) Run(ctx context.Context, name string, image string, cmd []string, volumes map[string]struct{}, ports nat.PortSet) error { |
| 86 | resp, err := d.client.ContainerCreate(ctx, &container.Config{Image: image, Volumes: volumes, ExposedPorts: ports, Cmd: cmd}, nil, nil, nil, name) |