container.go 18 KB

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