import "github.com/docker/docker/api/types/container" config := &container.HostConfig{ Memory: 1073741824, // 1GB of memory NetworkMode: "host", // use host networking Binds: []string{"/hostDir:/containerDir"}, // mount the host directory to the container }
import "github.com/docker/docker/api/types/container" config := &container.HostConfig{ RestartPolicy: container.RestartPolicy{ Name: "on-failure", // restart on failure MaximumRetryCount: 3, // try up to 3 times }, Resources: container.Resources{ Memory: 536870912, // 512MB of memory NanoCPUs: 1000000000, // 1 CPU Devices: []container.DeviceMapping{ { PathOnHost: "/dev/device", PathInContainer: "/dev/device", CgroupPermissions: "rwm", }, }, }, }In this example, we are configuring a container to restart on failure up to 3 times, limit the memory to 512MB and CPU to 1, and map a device from the host to the container. These settings are also defined in a HostConfig struct.