import ( "github.com/docker/docker/api/types" "github.com/docker/docker/client" "github.com/docker/docker/container" "golang.org/x/net/context" ) func main() { cli, err := client.NewEnvClient() if err != nil { panic(err) } ctx := context.Background() containerID := "my_container" c, err := container.GetContainer(ctx, containerID, cli) if err != nil { panic(err) } err = c.Unlock(ctx) if err != nil { panic(err) } }
import ( "github.com/docker/docker/api/types" "github.com/docker/docker/client" "github.com/docker/docker/container" "golang.org/x/net/context" ) func main() { cli, err := client.NewEnvClient() if err != nil { panic(err) } ctx := context.Background() imageName := "ubuntu:latest" config := &container.Config{ Image: imageName, Cmd: []string{"echo", "hello world"}, } hostConfig := &container.HostConfig{ AutoRemove: true, } c, err := container.CreateContainer(ctx, config, hostConfig, nil, "my_container", cli) if err != nil { panic(err) } err = c.Unlock(ctx) if err != nil { panic(err) } }In this example, we create a new container by specifying its configuration and host configuration. We then unlock the container so that it can be modified or deleted.