containerConfig := &types.ContainerConfig{ Image: "nginx", Hostname: "my-nginx-container", } hostConfig := &types.HostConfig{ NetworkMode: "bridge", DNS: []string{"8.8.8.8", "8.8.4.4"}, } containerOptions := types.ContainerCreateConfig{ Config: containerConfig, HostConfig: hostConfig, } resp, err := cli.ContainerCreate(ctx, containerOptions)
containerConfig := &types.ContainerConfig{ Image: "my-app", } hostConfig := &types.HostConfig{ Resources: types.Resources{ Memory: 1024 * 1024 * 100, // 100 MB NanoCPUs: 500000000, // 0.5 CPUs }, } containerOptions := types.ContainerCreateConfig{ Config: containerConfig, HostConfig: hostConfig, } resp, err := cli.ContainerCreate(ctx, containerOptions)In this example, we again define the container configuration options (e.g. image), but this time we specify the desired resource constraints in the `HostConfig` object. We use the `Resources` type to specify memory and CPU constraints in a platform-independent way. Finally, we pass both the container and host configurations to the `ContainerCreateConfig` object that we use to create the container.