container.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package libcontainer
  2. import (
  3. "github.com/dotcloud/docker/pkg/libcontainer/cgroups"
  4. "github.com/dotcloud/docker/pkg/libcontainer/devices"
  5. )
  6. // Context is a generic key value pair that allows arbatrary data to be sent
  7. type Context map[string]string
  8. // Container defines configuration options for executing a process inside a contained environment
  9. type Container struct {
  10. // Hostname optionally sets the container's hostname if provided
  11. Hostname string `json:"hostname,omitempty"`
  12. // ReadonlyFs will remount the container's rootfs as readonly where only externally mounted
  13. // bind mounts are writtable
  14. ReadonlyFs bool `json:"readonly_fs,omitempty"`
  15. // NoPivotRoot will use MS_MOVE and a chroot to jail the process into the container's rootfs
  16. // This is a common option when the container is running in ramdisk
  17. NoPivotRoot bool `json:"no_pivot_root,omitempty"`
  18. // User will set the uid and gid of the executing process running inside the container
  19. User string `json:"user,omitempty"`
  20. // WorkingDir will change the processes current working directory inside the container's rootfs
  21. WorkingDir string `json:"working_dir,omitempty"`
  22. // Env will populate the processes environment with the provided values
  23. // Any values from the parent processes will be cleared before the values
  24. // provided in Env are provided to the process
  25. Env []string `json:"environment,omitempty"`
  26. // Tty when true will allocate a pty slave on the host for access by the container's process
  27. // and ensure that it is mounted inside the container's rootfs
  28. Tty bool `json:"tty,omitempty"`
  29. // Namespaces specifies the container's namespaces that it should setup when cloning the init process
  30. // If a namespace is not provided that namespace is shared from the container's parent process
  31. Namespaces map[string]bool `json:"namespaces,omitempty"`
  32. // Capabilities specify the capabilities to keep when executing the process inside the container
  33. // All capbilities not specified will be dropped from the processes capability mask
  34. Capabilities []string `json:"capabilities,omitempty"`
  35. // Networks specifies the container's network setup to be created
  36. Networks []*Network `json:"networks,omitempty"`
  37. // Routes can be specified to create entries in the route table as the container is started
  38. Routes []*Route `json:"routes,omitempty"`
  39. // Cgroups specifies specific cgroup settings for the various subsystems that the container is
  40. // placed into to limit the resources the container has available
  41. Cgroups *cgroups.Cgroup `json:"cgroups,omitempty"`
  42. // Context is a generic key value format that allows for additional settings to be passed
  43. // on the container's creation
  44. // This is commonly used to specify apparmor profiles, selinux labels, and different restrictions
  45. // placed on the container's processes
  46. Context Context `json:"context,omitempty"`
  47. // Mounts specify additional source and destination paths that will be mounted inside the container's
  48. // rootfs and mount namespace if specified
  49. Mounts Mounts `json:"mounts,omitempty"`
  50. // The device nodes that should be automatically created within the container upon container start. Note, make sure that the node is marked as allowed in the cgroup as well!
  51. DeviceNodes []*devices.Device `json:"device_nodes,omitempty"`
  52. }
  53. // Network defines configuration for a container's networking stack
  54. //
  55. // The network configuration can be omited from a container causing the
  56. // container to be setup with the host's networking stack
  57. type Network struct {
  58. // Type sets the networks type, commonly veth and loopback
  59. Type string `json:"type,omitempty"`
  60. // Context is a generic key value format for setting additional options that are specific to
  61. // the network type
  62. Context Context `json:"context,omitempty"`
  63. // Address contains the IP and mask to set on the network interface
  64. Address string `json:"address,omitempty"`
  65. // Gateway sets the gateway address that is used as the default for the interface
  66. Gateway string `json:"gateway,omitempty"`
  67. // Mtu sets the mtu value for the interface and will be mirrored on both the host and
  68. // container's interfaces if a pair is created, specifically in the case of type veth
  69. Mtu int `json:"mtu,omitempty"`
  70. }
  71. // Routes can be specified to create entries in the route table as the container is started
  72. //
  73. // All of destination, source, and gateway should be either IPv4 or IPv6.
  74. // One of the three options must be present, and ommitted entries will use their
  75. // IP family default for the route table. For IPv4 for example, setting the
  76. // gateway to 1.2.3.4 and the interface to eth0 will set up a standard
  77. // destination of 0.0.0.0(or *) when viewed in the route table.
  78. type Route struct {
  79. // Sets the destination and mask, should be a CIDR. Accepts IPv4 and IPv6
  80. Destination string `json:"destination,omitempty"`
  81. // Sets the source and mask, should be a CIDR. Accepts IPv4 and IPv6
  82. Source string `json:"source,omitempty"`
  83. // Sets the gateway. Accepts IPv4 and IPv6
  84. Gateway string `json:"gateway,omitempty"`
  85. // The device to set this route up for, for example: eth0
  86. InterfaceName string `json:"interface_name,omitempty"`
  87. }