config.go 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package container // import "github.com/docker/docker/api/types/container"
  2. import (
  3. "io"
  4. "time"
  5. "github.com/docker/docker/api/types/strslice"
  6. "github.com/docker/go-connections/nat"
  7. )
  8. // MinimumDuration puts a minimum on user configured duration.
  9. // This is to prevent API error on time unit. For example, API may
  10. // set 3 as healthcheck interval with intention of 3 seconds, but
  11. // Docker interprets it as 3 nanoseconds.
  12. const MinimumDuration = 1 * time.Millisecond
  13. // StopOptions holds the options to stop or restart a container.
  14. type StopOptions struct {
  15. // Signal (optional) is the signal to send to the container to (gracefully)
  16. // stop it before forcibly terminating the container with SIGKILL after the
  17. // timeout expires. If not value is set, the default (SIGTERM) is used.
  18. Signal string `json:",omitempty"`
  19. // Timeout (optional) is the timeout (in seconds) to wait for the container
  20. // to stop gracefully before forcibly terminating it with SIGKILL.
  21. //
  22. // - Use nil to use the default timeout (10 seconds).
  23. // - Use '-1' to wait indefinitely.
  24. // - Use '0' to not wait for the container to exit gracefully, and
  25. // immediately proceeds to forcibly terminating the container.
  26. // - Other positive values are used as timeout (in seconds).
  27. Timeout *int `json:",omitempty"`
  28. }
  29. // HealthConfig holds configuration settings for the HEALTHCHECK feature.
  30. type HealthConfig struct {
  31. // Test is the test to perform to check that the container is healthy.
  32. // An empty slice means to inherit the default.
  33. // The options are:
  34. // {} : inherit healthcheck
  35. // {"NONE"} : disable healthcheck
  36. // {"CMD", args...} : exec arguments directly
  37. // {"CMD-SHELL", command} : run command with system's default shell
  38. Test []string `json:",omitempty"`
  39. // Zero means to inherit. Durations are expressed as integer nanoseconds.
  40. Interval time.Duration `json:",omitempty"` // Interval is the time to wait between checks.
  41. Timeout time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung.
  42. StartPeriod time.Duration `json:",omitempty"` // The start period for the container to initialize before the retries starts to count down.
  43. StartInterval time.Duration `json:",omitempty"` // The interval to attempt healthchecks at during the start period
  44. // Retries is the number of consecutive failures needed to consider a container as unhealthy.
  45. // Zero means inherit.
  46. Retries int `json:",omitempty"`
  47. }
  48. // ExecStartOptions holds the options to start container's exec.
  49. type ExecStartOptions struct {
  50. Stdin io.Reader
  51. Stdout io.Writer
  52. Stderr io.Writer
  53. ConsoleSize *[2]uint `json:",omitempty"`
  54. }
  55. // Config contains the configuration data about a container.
  56. // It should hold only portable information about the container.
  57. // Here, "portable" means "independent from the host we are running on".
  58. // Non-portable information *should* appear in HostConfig.
  59. // All fields added to this struct must be marked `omitempty` to keep getting
  60. // predictable hashes from the old `v1Compatibility` configuration.
  61. type Config struct {
  62. Hostname string // Hostname
  63. Domainname string // Domainname
  64. User string // User that will run the command(s) inside the container, also support user:group
  65. AttachStdin bool // Attach the standard input, makes possible user interaction
  66. AttachStdout bool // Attach the standard output
  67. AttachStderr bool // Attach the standard error
  68. ExposedPorts nat.PortSet `json:",omitempty"` // List of exposed ports
  69. Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
  70. OpenStdin bool // Open stdin
  71. StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
  72. Env []string // List of environment variable to set in the container
  73. Cmd strslice.StrSlice // Command to run when starting the container
  74. Healthcheck *HealthConfig `json:",omitempty"` // Healthcheck describes how to check the container is healthy
  75. ArgsEscaped bool `json:",omitempty"` // True if command is already escaped (meaning treat as a command line) (Windows specific).
  76. Image string // Name of the image as it was passed by the operator (e.g. could be symbolic)
  77. Volumes map[string]struct{} // List of volumes (mounts) used for the container
  78. WorkingDir string // Current directory (PWD) in the command will be launched
  79. Entrypoint strslice.StrSlice // Entrypoint to run when starting the container
  80. NetworkDisabled bool `json:",omitempty"` // Is network disabled
  81. MacAddress string `json:",omitempty"` // Mac Address of the container
  82. OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile
  83. Labels map[string]string // List of labels set to this container
  84. StopSignal string `json:",omitempty"` // Signal to stop a container
  85. StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container
  86. Shell strslice.StrSlice `json:",omitempty"` // Shell for shell-form of RUN, CMD, ENTRYPOINT
  87. }