container.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. package container
  2. import (
  3. "errors"
  4. "fmt"
  5. "net"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "github.com/Sirupsen/logrus"
  10. "github.com/docker/distribution/reference"
  11. "github.com/docker/docker/api/types"
  12. enginecontainer "github.com/docker/docker/api/types/container"
  13. "github.com/docker/docker/api/types/events"
  14. "github.com/docker/docker/api/types/filters"
  15. enginemount "github.com/docker/docker/api/types/mount"
  16. "github.com/docker/docker/api/types/network"
  17. volumetypes "github.com/docker/docker/api/types/volume"
  18. executorpkg "github.com/docker/docker/daemon/cluster/executor"
  19. clustertypes "github.com/docker/docker/daemon/cluster/provider"
  20. "github.com/docker/go-connections/nat"
  21. netconst "github.com/docker/libnetwork/datastore"
  22. "github.com/docker/swarmkit/agent/exec"
  23. "github.com/docker/swarmkit/api"
  24. "github.com/docker/swarmkit/template"
  25. gogotypes "github.com/gogo/protobuf/types"
  26. )
  27. const (
  28. // Explicitly use the kernel's default setting for CPU quota of 100ms.
  29. // https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt
  30. cpuQuotaPeriod = 100 * time.Millisecond
  31. // systemLabelPrefix represents the reserved namespace for system labels.
  32. systemLabelPrefix = "com.docker.swarm"
  33. )
  34. // containerConfig converts task properties into docker container compatible
  35. // components.
  36. type containerConfig struct {
  37. task *api.Task
  38. networksAttachments map[string]*api.NetworkAttachment
  39. }
  40. // newContainerConfig returns a validated container config. No methods should
  41. // return an error if this function returns without error.
  42. func newContainerConfig(t *api.Task) (*containerConfig, error) {
  43. var c containerConfig
  44. return &c, c.setTask(t)
  45. }
  46. func (c *containerConfig) setTask(t *api.Task) error {
  47. if t.Spec.GetContainer() == nil && t.Spec.GetAttachment() == nil {
  48. return exec.ErrRuntimeUnsupported
  49. }
  50. container := t.Spec.GetContainer()
  51. if container != nil {
  52. if container.Image == "" {
  53. return ErrImageRequired
  54. }
  55. if err := validateMounts(container.Mounts); err != nil {
  56. return err
  57. }
  58. }
  59. // index the networks by name
  60. c.networksAttachments = make(map[string]*api.NetworkAttachment, len(t.Networks))
  61. for _, attachment := range t.Networks {
  62. c.networksAttachments[attachment.Network.Spec.Annotations.Name] = attachment
  63. }
  64. c.task = t
  65. if t.Spec.GetContainer() != nil {
  66. preparedSpec, err := template.ExpandContainerSpec(t)
  67. if err != nil {
  68. return err
  69. }
  70. c.task.Spec.Runtime = &api.TaskSpec_Container{
  71. Container: preparedSpec,
  72. }
  73. }
  74. return nil
  75. }
  76. func (c *containerConfig) id() string {
  77. attachment := c.task.Spec.GetAttachment()
  78. if attachment == nil {
  79. return ""
  80. }
  81. return attachment.ContainerID
  82. }
  83. func (c *containerConfig) taskID() string {
  84. return c.task.ID
  85. }
  86. func (c *containerConfig) endpoint() *api.Endpoint {
  87. return c.task.Endpoint
  88. }
  89. func (c *containerConfig) spec() *api.ContainerSpec {
  90. return c.task.Spec.GetContainer()
  91. }
  92. func (c *containerConfig) nameOrID() string {
  93. if c.task.Spec.GetContainer() != nil {
  94. return c.name()
  95. }
  96. return c.id()
  97. }
  98. func (c *containerConfig) name() string {
  99. if c.task.Annotations.Name != "" {
  100. // if set, use the container Annotations.Name field, set in the orchestrator.
  101. return c.task.Annotations.Name
  102. }
  103. slot := fmt.Sprint(c.task.Slot)
  104. if slot == "" || c.task.Slot == 0 {
  105. slot = c.task.NodeID
  106. }
  107. // fallback to service.slot.id.
  108. return fmt.Sprintf("%s.%s.%s", c.task.ServiceAnnotations.Name, slot, c.task.ID)
  109. }
  110. func (c *containerConfig) image() string {
  111. raw := c.spec().Image
  112. ref, err := reference.ParseNormalizedNamed(raw)
  113. if err != nil {
  114. return raw
  115. }
  116. return reference.FamiliarString(reference.TagNameOnly(ref))
  117. }
  118. func (c *containerConfig) portBindings() nat.PortMap {
  119. portBindings := nat.PortMap{}
  120. if c.task.Endpoint == nil {
  121. return portBindings
  122. }
  123. for _, portConfig := range c.task.Endpoint.Ports {
  124. if portConfig.PublishMode != api.PublishModeHost {
  125. continue
  126. }
  127. port := nat.Port(fmt.Sprintf("%d/%s", portConfig.TargetPort, strings.ToLower(portConfig.Protocol.String())))
  128. binding := []nat.PortBinding{
  129. {},
  130. }
  131. if portConfig.PublishedPort != 0 {
  132. binding[0].HostPort = strconv.Itoa(int(portConfig.PublishedPort))
  133. }
  134. portBindings[port] = binding
  135. }
  136. return portBindings
  137. }
  138. func (c *containerConfig) exposedPorts() map[nat.Port]struct{} {
  139. exposedPorts := make(map[nat.Port]struct{})
  140. if c.task.Endpoint == nil {
  141. return exposedPorts
  142. }
  143. for _, portConfig := range c.task.Endpoint.Ports {
  144. if portConfig.PublishMode != api.PublishModeHost {
  145. continue
  146. }
  147. port := nat.Port(fmt.Sprintf("%d/%s", portConfig.TargetPort, strings.ToLower(portConfig.Protocol.String())))
  148. exposedPorts[port] = struct{}{}
  149. }
  150. return exposedPorts
  151. }
  152. func (c *containerConfig) config() *enginecontainer.Config {
  153. config := &enginecontainer.Config{
  154. Labels: c.labels(),
  155. StopSignal: c.spec().StopSignal,
  156. Tty: c.spec().TTY,
  157. OpenStdin: c.spec().OpenStdin,
  158. User: c.spec().User,
  159. Env: c.spec().Env,
  160. Hostname: c.spec().Hostname,
  161. WorkingDir: c.spec().Dir,
  162. Image: c.image(),
  163. ExposedPorts: c.exposedPorts(),
  164. Healthcheck: c.healthcheck(),
  165. }
  166. if len(c.spec().Command) > 0 {
  167. // If Command is provided, we replace the whole invocation with Command
  168. // by replacing Entrypoint and specifying Cmd. Args is ignored in this
  169. // case.
  170. config.Entrypoint = append(config.Entrypoint, c.spec().Command...)
  171. config.Cmd = append(config.Cmd, c.spec().Args...)
  172. } else if len(c.spec().Args) > 0 {
  173. // In this case, we assume the image has an Entrypoint and Args
  174. // specifies the arguments for that entrypoint.
  175. config.Cmd = c.spec().Args
  176. }
  177. return config
  178. }
  179. func (c *containerConfig) labels() map[string]string {
  180. var (
  181. system = map[string]string{
  182. "task": "", // mark as cluster task
  183. "task.id": c.task.ID,
  184. "task.name": c.name(),
  185. "node.id": c.task.NodeID,
  186. "service.id": c.task.ServiceID,
  187. "service.name": c.task.ServiceAnnotations.Name,
  188. }
  189. labels = make(map[string]string)
  190. )
  191. // base labels are those defined in the spec.
  192. for k, v := range c.spec().Labels {
  193. labels[k] = v
  194. }
  195. // we then apply the overrides from the task, which may be set via the
  196. // orchestrator.
  197. for k, v := range c.task.Annotations.Labels {
  198. labels[k] = v
  199. }
  200. // finally, we apply the system labels, which override all labels.
  201. for k, v := range system {
  202. labels[strings.Join([]string{systemLabelPrefix, k}, ".")] = v
  203. }
  204. return labels
  205. }
  206. func (c *containerConfig) mounts() []enginemount.Mount {
  207. var r []enginemount.Mount
  208. for _, mount := range c.spec().Mounts {
  209. r = append(r, convertMount(mount))
  210. }
  211. return r
  212. }
  213. func convertMount(m api.Mount) enginemount.Mount {
  214. mount := enginemount.Mount{
  215. Source: m.Source,
  216. Target: m.Target,
  217. ReadOnly: m.ReadOnly,
  218. }
  219. switch m.Type {
  220. case api.MountTypeBind:
  221. mount.Type = enginemount.TypeBind
  222. case api.MountTypeVolume:
  223. mount.Type = enginemount.TypeVolume
  224. case api.MountTypeTmpfs:
  225. mount.Type = enginemount.TypeTmpfs
  226. }
  227. if m.BindOptions != nil {
  228. mount.BindOptions = &enginemount.BindOptions{}
  229. switch m.BindOptions.Propagation {
  230. case api.MountPropagationRPrivate:
  231. mount.BindOptions.Propagation = enginemount.PropagationRPrivate
  232. case api.MountPropagationPrivate:
  233. mount.BindOptions.Propagation = enginemount.PropagationPrivate
  234. case api.MountPropagationRSlave:
  235. mount.BindOptions.Propagation = enginemount.PropagationRSlave
  236. case api.MountPropagationSlave:
  237. mount.BindOptions.Propagation = enginemount.PropagationSlave
  238. case api.MountPropagationRShared:
  239. mount.BindOptions.Propagation = enginemount.PropagationRShared
  240. case api.MountPropagationShared:
  241. mount.BindOptions.Propagation = enginemount.PropagationShared
  242. }
  243. }
  244. if m.VolumeOptions != nil {
  245. mount.VolumeOptions = &enginemount.VolumeOptions{
  246. NoCopy: m.VolumeOptions.NoCopy,
  247. }
  248. if m.VolumeOptions.Labels != nil {
  249. mount.VolumeOptions.Labels = make(map[string]string, len(m.VolumeOptions.Labels))
  250. for k, v := range m.VolumeOptions.Labels {
  251. mount.VolumeOptions.Labels[k] = v
  252. }
  253. }
  254. if m.VolumeOptions.DriverConfig != nil {
  255. mount.VolumeOptions.DriverConfig = &enginemount.Driver{
  256. Name: m.VolumeOptions.DriverConfig.Name,
  257. }
  258. if m.VolumeOptions.DriverConfig.Options != nil {
  259. mount.VolumeOptions.DriverConfig.Options = make(map[string]string, len(m.VolumeOptions.DriverConfig.Options))
  260. for k, v := range m.VolumeOptions.DriverConfig.Options {
  261. mount.VolumeOptions.DriverConfig.Options[k] = v
  262. }
  263. }
  264. }
  265. }
  266. if m.TmpfsOptions != nil {
  267. mount.TmpfsOptions = &enginemount.TmpfsOptions{
  268. SizeBytes: m.TmpfsOptions.SizeBytes,
  269. Mode: m.TmpfsOptions.Mode,
  270. }
  271. }
  272. return mount
  273. }
  274. func (c *containerConfig) healthcheck() *enginecontainer.HealthConfig {
  275. hcSpec := c.spec().Healthcheck
  276. if hcSpec == nil {
  277. return nil
  278. }
  279. interval, _ := gogotypes.DurationFromProto(hcSpec.Interval)
  280. timeout, _ := gogotypes.DurationFromProto(hcSpec.Timeout)
  281. startPeriod, _ := gogotypes.DurationFromProto(hcSpec.StartPeriod)
  282. return &enginecontainer.HealthConfig{
  283. Test: hcSpec.Test,
  284. Interval: interval,
  285. Timeout: timeout,
  286. Retries: int(hcSpec.Retries),
  287. StartPeriod: startPeriod,
  288. }
  289. }
  290. func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
  291. hc := &enginecontainer.HostConfig{
  292. Resources: c.resources(),
  293. GroupAdd: c.spec().Groups,
  294. PortBindings: c.portBindings(),
  295. Mounts: c.mounts(),
  296. ReadonlyRootfs: c.spec().ReadOnly,
  297. }
  298. if c.spec().DNSConfig != nil {
  299. hc.DNS = c.spec().DNSConfig.Nameservers
  300. hc.DNSSearch = c.spec().DNSConfig.Search
  301. hc.DNSOptions = c.spec().DNSConfig.Options
  302. }
  303. c.applyPrivileges(hc)
  304. // The format of extra hosts on swarmkit is specified in:
  305. // http://man7.org/linux/man-pages/man5/hosts.5.html
  306. // IP_address canonical_hostname [aliases...]
  307. // However, the format of ExtraHosts in HostConfig is
  308. // <host>:<ip>
  309. // We need to do the conversion here
  310. // (Alias is ignored for now)
  311. for _, entry := range c.spec().Hosts {
  312. parts := strings.Fields(entry)
  313. if len(parts) > 1 {
  314. hc.ExtraHosts = append(hc.ExtraHosts, fmt.Sprintf("%s:%s", parts[1], parts[0]))
  315. }
  316. }
  317. if c.task.LogDriver != nil {
  318. hc.LogConfig = enginecontainer.LogConfig{
  319. Type: c.task.LogDriver.Name,
  320. Config: c.task.LogDriver.Options,
  321. }
  322. }
  323. if len(c.task.Networks) > 0 {
  324. labels := c.task.Networks[0].Network.Spec.Annotations.Labels
  325. name := c.task.Networks[0].Network.Spec.Annotations.Name
  326. if v, ok := labels["com.docker.swarm.predefined"]; ok && v == "true" {
  327. hc.NetworkMode = enginecontainer.NetworkMode(name)
  328. }
  329. }
  330. return hc
  331. }
  332. // This handles the case of volumes that are defined inside a service Mount
  333. func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *volumetypes.VolumesCreateBody {
  334. var (
  335. driverName string
  336. driverOpts map[string]string
  337. labels map[string]string
  338. )
  339. if mount.VolumeOptions != nil && mount.VolumeOptions.DriverConfig != nil {
  340. driverName = mount.VolumeOptions.DriverConfig.Name
  341. driverOpts = mount.VolumeOptions.DriverConfig.Options
  342. labels = mount.VolumeOptions.Labels
  343. }
  344. if mount.VolumeOptions != nil {
  345. return &volumetypes.VolumesCreateBody{
  346. Name: mount.Source,
  347. Driver: driverName,
  348. DriverOpts: driverOpts,
  349. Labels: labels,
  350. }
  351. }
  352. return nil
  353. }
  354. func (c *containerConfig) resources() enginecontainer.Resources {
  355. resources := enginecontainer.Resources{}
  356. // If no limits are specified let the engine use its defaults.
  357. //
  358. // TODO(aluzzardi): We might want to set some limits anyway otherwise
  359. // "unlimited" tasks will step over the reservation of other tasks.
  360. r := c.task.Spec.Resources
  361. if r == nil || r.Limits == nil {
  362. return resources
  363. }
  364. if r.Limits.MemoryBytes > 0 {
  365. resources.Memory = r.Limits.MemoryBytes
  366. }
  367. if r.Limits.NanoCPUs > 0 {
  368. // CPU Period must be set in microseconds.
  369. resources.CPUPeriod = int64(cpuQuotaPeriod / time.Microsecond)
  370. resources.CPUQuota = r.Limits.NanoCPUs * resources.CPUPeriod / 1e9
  371. }
  372. return resources
  373. }
  374. // Docker daemon supports just 1 network during container create.
  375. func (c *containerConfig) createNetworkingConfig(b executorpkg.Backend) *network.NetworkingConfig {
  376. var networks []*api.NetworkAttachment
  377. if c.task.Spec.GetContainer() != nil || c.task.Spec.GetAttachment() != nil {
  378. networks = c.task.Networks
  379. }
  380. epConfig := make(map[string]*network.EndpointSettings)
  381. if len(networks) > 0 {
  382. epConfig[networks[0].Network.Spec.Annotations.Name] = getEndpointConfig(networks[0], b)
  383. }
  384. return &network.NetworkingConfig{EndpointsConfig: epConfig}
  385. }
  386. // TODO: Merge this function with createNetworkingConfig after daemon supports multiple networks in container create
  387. func (c *containerConfig) connectNetworkingConfig(b executorpkg.Backend) *network.NetworkingConfig {
  388. var networks []*api.NetworkAttachment
  389. if c.task.Spec.GetContainer() != nil {
  390. networks = c.task.Networks
  391. }
  392. // First network is used during container create. Other networks are used in "docker network connect"
  393. if len(networks) < 2 {
  394. return nil
  395. }
  396. epConfig := make(map[string]*network.EndpointSettings)
  397. for _, na := range networks[1:] {
  398. epConfig[na.Network.Spec.Annotations.Name] = getEndpointConfig(na, b)
  399. }
  400. return &network.NetworkingConfig{EndpointsConfig: epConfig}
  401. }
  402. func getEndpointConfig(na *api.NetworkAttachment, b executorpkg.Backend) *network.EndpointSettings {
  403. var ipv4, ipv6 string
  404. for _, addr := range na.Addresses {
  405. ip, _, err := net.ParseCIDR(addr)
  406. if err != nil {
  407. continue
  408. }
  409. if ip.To4() != nil {
  410. ipv4 = ip.String()
  411. continue
  412. }
  413. if ip.To16() != nil {
  414. ipv6 = ip.String()
  415. }
  416. }
  417. n := &network.EndpointSettings{
  418. NetworkID: na.Network.ID,
  419. IPAMConfig: &network.EndpointIPAMConfig{
  420. IPv4Address: ipv4,
  421. IPv6Address: ipv6,
  422. },
  423. }
  424. if v, ok := na.Network.Spec.Annotations.Labels["com.docker.swarm.predefined"]; ok && v == "true" {
  425. if ln, err := b.FindNetwork(na.Network.Spec.Annotations.Name); err == nil {
  426. n.NetworkID = ln.ID()
  427. }
  428. }
  429. return n
  430. }
  431. func (c *containerConfig) virtualIP(networkID string) string {
  432. if c.task.Endpoint == nil {
  433. return ""
  434. }
  435. for _, eVip := range c.task.Endpoint.VirtualIPs {
  436. // We only support IPv4 VIPs for now.
  437. if eVip.NetworkID == networkID {
  438. vip, _, err := net.ParseCIDR(eVip.Addr)
  439. if err != nil {
  440. return ""
  441. }
  442. return vip.String()
  443. }
  444. }
  445. return ""
  446. }
  447. func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig {
  448. if len(c.task.Networks) == 0 {
  449. return nil
  450. }
  451. logrus.Debugf("Creating service config in agent for t = %+v", c.task)
  452. svcCfg := &clustertypes.ServiceConfig{
  453. Name: c.task.ServiceAnnotations.Name,
  454. Aliases: make(map[string][]string),
  455. ID: c.task.ServiceID,
  456. VirtualAddresses: make(map[string]*clustertypes.VirtualAddress),
  457. }
  458. for _, na := range c.task.Networks {
  459. svcCfg.VirtualAddresses[na.Network.ID] = &clustertypes.VirtualAddress{
  460. // We support only IPv4 virtual IP for now.
  461. IPv4: c.virtualIP(na.Network.ID),
  462. }
  463. if len(na.Aliases) > 0 {
  464. svcCfg.Aliases[na.Network.ID] = na.Aliases
  465. }
  466. }
  467. if c.task.Endpoint != nil {
  468. for _, ePort := range c.task.Endpoint.Ports {
  469. if ePort.PublishMode != api.PublishModeIngress {
  470. continue
  471. }
  472. svcCfg.ExposedPorts = append(svcCfg.ExposedPorts, &clustertypes.PortConfig{
  473. Name: ePort.Name,
  474. Protocol: int32(ePort.Protocol),
  475. TargetPort: ePort.TargetPort,
  476. PublishedPort: ePort.PublishedPort,
  477. })
  478. }
  479. }
  480. return svcCfg
  481. }
  482. // networks returns a list of network names attached to the container. The
  483. // returned name can be used to lookup the corresponding network create
  484. // options.
  485. func (c *containerConfig) networks() []string {
  486. var networks []string
  487. for name := range c.networksAttachments {
  488. networks = append(networks, name)
  489. }
  490. return networks
  491. }
  492. func (c *containerConfig) networkCreateRequest(name string) (clustertypes.NetworkCreateRequest, error) {
  493. na, ok := c.networksAttachments[name]
  494. if !ok {
  495. return clustertypes.NetworkCreateRequest{}, errors.New("container: unknown network referenced")
  496. }
  497. options := types.NetworkCreate{
  498. // ID: na.Network.ID,
  499. Labels: na.Network.Spec.Annotations.Labels,
  500. Internal: na.Network.Spec.Internal,
  501. Attachable: na.Network.Spec.Attachable,
  502. Ingress: na.Network.Spec.Ingress,
  503. EnableIPv6: na.Network.Spec.Ipv6Enabled,
  504. CheckDuplicate: true,
  505. Scope: netconst.SwarmScope,
  506. }
  507. if na.Network.Spec.ConfigFrom != "" {
  508. options.ConfigFrom = &network.ConfigReference{
  509. Network: na.Network.Spec.ConfigFrom,
  510. }
  511. }
  512. if na.Network.DriverState != nil {
  513. options.Driver = na.Network.DriverState.Name
  514. options.Options = na.Network.DriverState.Options
  515. }
  516. if na.Network.IPAM != nil {
  517. options.IPAM = &network.IPAM{
  518. Driver: na.Network.IPAM.Driver.Name,
  519. Options: na.Network.IPAM.Driver.Options,
  520. }
  521. for _, ic := range na.Network.IPAM.Configs {
  522. c := network.IPAMConfig{
  523. Subnet: ic.Subnet,
  524. IPRange: ic.Range,
  525. Gateway: ic.Gateway,
  526. }
  527. options.IPAM.Config = append(options.IPAM.Config, c)
  528. }
  529. }
  530. return clustertypes.NetworkCreateRequest{
  531. ID: na.Network.ID,
  532. NetworkCreateRequest: types.NetworkCreateRequest{
  533. Name: name,
  534. NetworkCreate: options,
  535. },
  536. }, nil
  537. }
  538. func (c *containerConfig) applyPrivileges(hc *enginecontainer.HostConfig) {
  539. privileges := c.spec().Privileges
  540. if privileges == nil {
  541. return
  542. }
  543. credentials := privileges.CredentialSpec
  544. if credentials != nil {
  545. switch credentials.Source.(type) {
  546. case *api.Privileges_CredentialSpec_File:
  547. hc.SecurityOpt = append(hc.SecurityOpt, "credentialspec=file://"+credentials.GetFile())
  548. case *api.Privileges_CredentialSpec_Registry:
  549. hc.SecurityOpt = append(hc.SecurityOpt, "credentialspec=registry://"+credentials.GetRegistry())
  550. }
  551. }
  552. selinux := privileges.SELinuxContext
  553. if selinux != nil {
  554. if selinux.Disable {
  555. hc.SecurityOpt = append(hc.SecurityOpt, "label=disable")
  556. }
  557. if selinux.User != "" {
  558. hc.SecurityOpt = append(hc.SecurityOpt, "label=user:"+selinux.User)
  559. }
  560. if selinux.Role != "" {
  561. hc.SecurityOpt = append(hc.SecurityOpt, "label=role:"+selinux.Role)
  562. }
  563. if selinux.Level != "" {
  564. hc.SecurityOpt = append(hc.SecurityOpt, "label=level:"+selinux.Level)
  565. }
  566. if selinux.Type != "" {
  567. hc.SecurityOpt = append(hc.SecurityOpt, "label=type:"+selinux.Type)
  568. }
  569. }
  570. }
  571. func (c containerConfig) eventFilter() filters.Args {
  572. filter := filters.NewArgs()
  573. filter.Add("type", events.ContainerEventType)
  574. filter.Add("name", c.name())
  575. filter.Add("label", fmt.Sprintf("%v.task.id=%v", systemLabelPrefix, c.task.ID))
  576. return filter
  577. }