forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_task_engine.go
662 lines (577 loc) · 23.1 KB
/
docker_task_engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
// The DockerTaskEngine is an abstraction over the DockerGoClient so that
// it does not have to know about tasks, only containers
package engine
import (
"errors"
"sync"
"time"
"golang.org/x/net/context"
"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/statemanager"
"github.com/aws/amazon-ecs-agent/agent/utils"
utilsync "github.com/aws/amazon-ecs-agent/agent/utils/sync"
)
const (
DOCKER_ENDPOINT_ENV_VARIABLE = "DOCKER_HOST"
DOCKER_DEFAULT_ENDPOINT = "unix:///var/run/docker.sock"
capabilityPrefix = "com.amazonaws.ecs.capability."
)
// The DockerTaskEngine interacts with docker to implement a task
// engine
type DockerTaskEngine struct {
// implements TaskEngine
cfg *config.Config
initialized bool
mustInitLock sync.Mutex
// state stores all tasks this task engine is aware of, including their
// current state and mappings to/from dockerId and name.
// This is used to checkpoint state to disk so tasks may survive agent
// failures or updates
state *dockerstate.DockerTaskEngineState
managedTasks map[string]*managedTask
taskStopGroup *utilsync.SequentialWaitGroup
events <-chan DockerContainerChangeEvent
containerEvents chan api.ContainerStateChange
taskEvents chan api.TaskStateChange
saver statemanager.Saver
client DockerClient
clientLock sync.Mutex
stopEngine context.CancelFunc
// processTasks is a mutex that the task engine must aquire before changing
// any task's state which it manages. Since this is a lock that encompasses
// all tasks, it must not aquire it for any significant duration
// The write mutex should be taken when adding and removing tasks from managedTasks.
processTasks sync.RWMutex
}
// NewDockerTaskEngine returns a created, but uninitialized, DockerTaskEngine.
// The distinction between created and initialized is that when created it may
// be serialized/deserialized, but it will not communicate with docker until it
// is also initialized.
func NewDockerTaskEngine(cfg *config.Config) *DockerTaskEngine {
dockerTaskEngine := &DockerTaskEngine{
cfg: cfg,
client: nil,
saver: statemanager.NewNoopStateManager(),
state: dockerstate.NewDockerTaskEngineState(),
managedTasks: make(map[string]*managedTask),
taskStopGroup: utilsync.NewSequentialWaitGroup(),
containerEvents: make(chan api.ContainerStateChange),
taskEvents: make(chan api.TaskStateChange),
}
return dockerTaskEngine
}
// UnmarshalJSON restores a previously marshaled task-engine state from json
func (engine *DockerTaskEngine) UnmarshalJSON(data []byte) error {
return engine.state.UnmarshalJSON(data)
}
// MarshalJSON marshals into state directly
func (engine *DockerTaskEngine) MarshalJSON() ([]byte, error) {
return engine.state.MarshalJSON()
}
// Init initializes a DockerTaskEngine such that it may communicate with docker
// and operate normally.
// This function must be called before any other function, except serializing and deserializing, can succeed without error.
func (engine *DockerTaskEngine) Init() error {
err := engine.initDockerClient()
if err != nil {
return err
}
// TODO, pass in a a context from main from background so that other things can stop us, not just the tests
ctx, cancel := context.WithCancel(context.TODO())
engine.stopEngine = cancel
// Open the event stream before we sync state so that e.g. if a container
// goes from running to stopped after we sync with it as "running" we still
// have the "went to stopped" event pending so we can be up to date.
err = engine.openEventstream(ctx)
if err != nil {
return err
}
engine.synchronizeState()
// Now catch up and start processing new events per normal
go engine.handleDockerEvents(ctx)
engine.initialized = true
return nil
}
func (engine *DockerTaskEngine) initDockerClient() error {
if engine.client != nil {
return nil
}
engine.clientLock.Lock()
defer engine.clientLock.Unlock()
if engine.client != nil {
return nil
}
client, err := NewDockerGoClient(nil, engine.cfg.EngineAuthType, engine.cfg.EngineAuthData)
if err != nil {
return err
}
engine.client = client
return nil
}
// SetDockerClient provides a way to override the client used for communication with docker as a testing hook.
func (engine *DockerTaskEngine) SetDockerClient(client DockerClient) {
engine.clientLock.Lock()
engine.clientLock.Unlock()
engine.client = client
}
// MustInit blocks and retries until an engine can be initialized.
func (engine *DockerTaskEngine) MustInit() {
if engine.initialized {
return
}
engine.mustInitLock.Lock()
defer engine.mustInitLock.Unlock()
errorOnce := sync.Once{}
taskEngineConnectBackoff := utils.NewSimpleBackoff(200*time.Millisecond, 2*time.Second, 0.20, 1.5)
utils.RetryWithBackoff(taskEngineConnectBackoff, func() error {
if engine.initialized {
return nil
}
err := engine.Init()
if err != nil {
errorOnce.Do(func() {
log.Error("Could not connect to docker daemon", "err", err)
})
}
return err
})
}
func (engine *DockerTaskEngine) SetSaver(saver statemanager.Saver) {
engine.saver = saver
}
// Shutdown makes a best-effort attempt to cleanup after the task engine.
// This should not be relied on for anything more complicated than testing.
func (engine *DockerTaskEngine) Shutdown() {
engine.stopEngine()
engine.Disable()
}
// Disable prevents this engine from managing any additional tasks.
func (engine *DockerTaskEngine) Disable() {
engine.processTasks.Lock()
}
// synchronizeState explicitly goes through each docker container stored in
// "state" and updates its KnownStatus appropriately, as well as queueing up
// events to push upstream.
func (engine *DockerTaskEngine) synchronizeState() {
engine.processTasks.Lock()
defer engine.processTasks.Unlock()
tasks := engine.state.AllTasks()
for _, task := range tasks {
conts, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
engine.startTask(task)
continue
}
for _, cont := range conts {
if cont.DockerId == "" {
log.Debug("Found container potentially created while we were down", "name", cont.DockerName)
// Figure out the dockerid
describedCont, err := engine.client.InspectContainer(cont.DockerName)
if err != nil {
log.Warn("Could not find matching container for expected", "name", cont.DockerName)
} else {
cont.DockerId = describedCont.ID
// update mappings that need dockerid
engine.state.AddContainer(cont, task)
}
}
if cont.DockerId != "" {
currentState, metadata := engine.client.DescribeContainer(cont.DockerId)
if metadata.Error != nil {
currentState = api.ContainerStopped
if !cont.Container.KnownTerminal() {
cont.Container.ApplyingError = api.NewNamedError(&ContainerVanishedError{})
log.Warn("Could not describe previously known container; assuming dead", "err", metadata.Error, "id", cont.DockerId, "name", cont.DockerName)
}
}
if currentState > cont.Container.KnownStatus {
cont.Container.KnownStatus = currentState
}
}
}
engine.startTask(task)
}
engine.saver.Save()
}
// CheckTaskState inspects the state of all containers within a task and writes
// their state to the managed task's container channel.
func (engine *DockerTaskEngine) CheckTaskState(task *api.Task) {
taskContainers, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
log.Warn("Could not check task state for task; no task in state", "task", task)
return
}
for _, container := range task.Containers {
dockerContainer, ok := taskContainers[container.Name]
if !ok {
continue
}
status, metadata := engine.client.DescribeContainer(dockerContainer.DockerId)
engine.processTasks.RLock()
managedTask, ok := engine.managedTasks[task.Arn]
engine.processTasks.RUnlock()
if ok {
managedTask.dockerMessages <- dockerContainerChange{
container: container,
event: DockerContainerChangeEvent{
Status: status,
DockerContainerMetadata: metadata,
},
}
}
}
}
// sweepTask deletes all the containers associated with a task
func (engine *DockerTaskEngine) sweepTask(task *api.Task) {
for _, cont := range task.Containers {
err := engine.removeContainer(task, cont)
if err != nil {
log.Debug("Unable to remove old container", "err", err, "task", task, "cont", cont)
}
}
}
func (engine *DockerTaskEngine) emitTaskEvent(task *api.Task, reason string) {
if !task.KnownStatus.BackendRecognized() {
return
}
if task.SentStatus >= task.KnownStatus {
log.Debug("Already sent task event; no need to re-send", "task", task.Arn, "event", task.KnownStatus.String())
return
}
event := api.TaskStateChange{
TaskArn: task.Arn,
Status: task.KnownStatus,
Reason: reason,
SentStatus: &task.SentStatus,
}
log.Info("Task change event", "event", event)
engine.taskEvents <- event
}
// startTask creates a managedTask construct to track the task and then begins
// pushing it towards its desired state when allowed startTask is protected by
// the processTasks lock of 'AddTask'. It should not be called from anywhere
// else and should exit quickly to allow AddTask to do more work.
func (engine *DockerTaskEngine) startTask(task *api.Task) {
// Create a channel that may be used to communicate with this task, survey
// what tasks need to be waited for for this one to start, and then spin off
// a goroutine to oversee this task
thisTask := engine.newManagedTask(task)
go thisTask.overseeTask()
}
// emitContainerEvent passes a given event up through the containerEvents channel if necessary.
// It will omit events the backend would not process and will perform best-effort deduplication of events.
func (engine *DockerTaskEngine) emitContainerEvent(task *api.Task, cont *api.Container, reason string) {
if !cont.KnownStatus.BackendRecognized() {
return
}
if cont.IsInternal {
return
}
if cont.SentStatus >= cont.KnownStatus {
log.Debug("Already sent container event; no need to re-send", "task", task.Arn, "container", cont.Name, "event", cont.KnownStatus.String())
return
}
if reason == "" && cont.ApplyingError != nil {
reason = cont.ApplyingError.Error()
}
event := api.ContainerStateChange{
TaskArn: task.Arn,
ContainerName: cont.Name,
Status: cont.KnownStatus,
ExitCode: cont.KnownExitCode,
PortBindings: cont.KnownPortBindings,
Reason: reason,
SentStatus: &cont.SentStatus,
}
log.Debug("Container change event", "event", event)
engine.containerEvents <- event
log.Debug("Container change event passed on", "event", event)
}
// openEventstream opens, but does not consume, the docker event stream
func (engine *DockerTaskEngine) openEventstream(ctx context.Context) error {
events, err := engine.client.ContainerEvents(ctx)
if err != nil {
return err
}
engine.events = events
return nil
}
// handleDockerEvents must be called after openEventstream; it processes each
// event that it reads from the docker eventstream
func (engine *DockerTaskEngine) handleDockerEvents(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case event := <-engine.events:
log.Debug("Handling a docker event", "event", event)
task, task_found := engine.state.TaskById(event.DockerId)
cont, container_found := engine.state.ContainerById(event.DockerId)
if !task_found || !container_found {
log.Debug("Event for container not managed", "dockerId", event.DockerId)
break
}
engine.processTasks.RLock()
managedTask, ok := engine.managedTasks[task.Arn]
if !ok {
log.Crit("Could not find managed task corresponding to a docker event", "event", event, "task", task)
}
log.Debug("Writing docker event to the associated task", "task", task, "event", event)
managedTask.dockerMessages <- dockerContainerChange{container: cont.Container, event: event}
log.Debug("Wrote docker event to the associated task", "task", task, "event", event)
engine.processTasks.RUnlock()
}
}
}
// TaskEvents returns channels to read task and container state changes. These
// changes should be read as soon as possible as them not being read will block
// processing the task referenced by the event.
func (engine *DockerTaskEngine) TaskEvents() (<-chan api.TaskStateChange, <-chan api.ContainerStateChange) {
return engine.taskEvents, engine.containerEvents
}
func (engine *DockerTaskEngine) AddTask(task *api.Task) error {
task.PostUnmarshalTask()
engine.processTasks.Lock()
defer engine.processTasks.Unlock()
existingTask, exists := engine.state.TaskByArn(task.Arn)
if !exists {
engine.state.AddTask(task)
engine.startTask(task)
} else {
engine.updateTask(existingTask, task)
}
return nil
}
type transitionApplyFunc (func(*api.Task, *api.Container) DockerContainerMetadata)
func tryApplyTransition(task *api.Task, container *api.Container, to api.ContainerStatus, f transitionApplyFunc) DockerContainerMetadata {
return f(task, container)
}
func (engine *DockerTaskEngine) ListTasks() ([]*api.Task, error) {
return engine.state.AllTasks(), nil
}
func (engine *DockerTaskEngine) pullContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Pulling container", "task", task, "container", container)
return engine.client.PullImage(container.Image)
}
func (engine *DockerTaskEngine) createContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Creating container", "task", task, "container", container)
client := engine.client
if container.DockerConfig.Version != nil {
client = client.WithVersion(dockerclient.DockerVersion(*container.DockerConfig.Version))
}
// Resolve HostConfig
// we have to do this in create, not start, because docker no longer handles
// merging create config with start hostconfig the same; e.g. memory limits
// get lost
containerMap, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
containerMap = make(map[string]*api.DockerContainer)
}
hostConfig, hcerr := task.DockerHostConfig(container, containerMap)
if hcerr != nil {
return DockerContainerMetadata{Error: api.NamedError(hcerr)}
}
config, err := task.DockerConfig(container)
if err != nil {
return DockerContainerMetadata{Error: api.NamedError(err)}
}
name := ""
for i := 0; i < len(container.Name); i++ {
c := container.Name[i]
if !((c <= '9' && c >= '0') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '-')) {
continue
}
name += string(c)
}
containerName := "ecs-" + task.Family + "-" + task.Version + "-" + name + "-" + utils.RandHex()
// Pre-add the container in case we stop before the next, more useful,
// AddContainer call. This ensures we have a way to get the container if
// we die before 'createContainer' returns because we can inspect by
// name
engine.state.AddContainer(&api.DockerContainer{DockerName: containerName, Container: container}, task)
metadata := client.CreateContainer(config, hostConfig, containerName)
if metadata.Error != nil {
return metadata
}
engine.state.AddContainer(&api.DockerContainer{DockerId: metadata.DockerId, DockerName: containerName, Container: container}, task)
log.Info("Created container successfully", "task", task, "container", container)
return metadata
}
func (engine *DockerTaskEngine) startContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Starting container", "task", task, "container", container)
client := engine.client
if container.DockerConfig.Version != nil {
client = client.WithVersion(dockerclient.DockerVersion(*container.DockerConfig.Version))
}
containerMap, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
return DockerContainerMetadata{Error: CannotXContainerError{"Start", "Container belongs to unrecognized task " + task.Arn}}
}
dockerContainer, ok := containerMap[container.Name]
if !ok {
return DockerContainerMetadata{Error: CannotXContainerError{"Start", "Container not recorded as created"}}
}
return client.StartContainer(dockerContainer.DockerId)
}
func (engine *DockerTaskEngine) stopContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Stopping container", "task", task, "container", container)
containerMap, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
return DockerContainerMetadata{Error: CannotXContainerError{"Stop", "Container belongs to unrecognized task " + task.Arn}}
}
dockerContainer, ok := containerMap[container.Name]
if !ok {
return DockerContainerMetadata{Error: CannotXContainerError{"Stop", "Container not recorded as created"}}
}
return engine.client.StopContainer(dockerContainer.DockerId)
}
func (engine *DockerTaskEngine) removeContainer(task *api.Task, container *api.Container) error {
log.Info("Removing container", "task", task, "container", container)
containerMap, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
return errors.New("No such task: " + task.Arn)
}
dockerContainer, ok := containerMap[container.Name]
if !ok {
return errors.New("No container named '" + container.Name + "' created in " + task.Arn)
}
return engine.client.RemoveContainer(dockerContainer.DockerId)
}
// updateTask determines if a new transition needs to be applied to the
// referenced task, and if needed applies it. It should not be called anywhere
// but from 'AddTask' and is protected by the processTasks lock there.
func (engine *DockerTaskEngine) updateTask(task *api.Task, update *api.Task) {
managedTask, ok := engine.managedTasks[task.Arn]
if !ok {
log.Crit("ACS message for a task we thought we managed, but don't!", "arn", task.Arn)
// Is this the right thing to do?
// Calling startTask should overwrite our bad 'state' data with the new
// task which we do manage.. but this is still scary and shouldn't have happened
engine.startTask(update)
return
}
// Keep the lock because sequence numbers cannot be correct unless they are
// also read in the order addtask was called
// This does block the engine's ability to ingest any new events (including
// stops for past tasks, ack!), but this is necessary for correctness
log.Debug("Putting update on the acs channel", "task", task.Arn, "status", update.DesiredStatus, "seqnum", update.StopSequenceNumber)
transition := acsTransition{desiredStatus: update.DesiredStatus}
transition.seqnum = update.StopSequenceNumber
managedTask.acsMessages <- transition
log.Debug("Update was taken off the acs channel", "task", task.Arn, "status", update.DesiredStatus)
}
func (engine *DockerTaskEngine) transitionFunctionMap() map[api.ContainerStatus]transitionApplyFunc {
return map[api.ContainerStatus]transitionApplyFunc{
api.ContainerPulled: engine.pullContainer,
api.ContainerCreated: engine.createContainer,
api.ContainerRunning: engine.startContainer,
api.ContainerStopped: engine.stopContainer,
}
}
// applyContainerState moves the container to the given state
func (engine *DockerTaskEngine) applyContainerState(task *api.Task, container *api.Container, nextState api.ContainerStatus) DockerContainerMetadata {
clog := log.New("task", task, "container", container)
transitionFunction, ok := engine.transitionFunctionMap()[nextState]
if !ok {
clog.Crit("Container desired to transition to an unsupported state", "state", nextState.String())
return DockerContainerMetadata{Error: &impossibleTransitionError{nextState}}
}
metadata := tryApplyTransition(task, container, nextState, transitionFunction)
if metadata.Error != nil {
clog.Info("Error transitioning container", "state", nextState.String())
} else {
clog.Debug("Transitioned container", "state", nextState.String())
engine.saver.Save()
}
return metadata
}
func (engine *DockerTaskEngine) transitionContainer(task *api.Task, container *api.Container, to api.ContainerStatus) {
// Let docker events operate async so that we can continue to handle ACS / other requests
// This is safe because 'applyContainerState' will not mutate the task
metadata := engine.applyContainerState(task, container, to)
engine.processTasks.RLock()
managedTask, ok := engine.managedTasks[task.Arn]
engine.processTasks.RUnlock()
if ok {
managedTask.dockerMessages <- dockerContainerChange{
container: container,
event: DockerContainerChangeEvent{
Status: to,
DockerContainerMetadata: metadata,
},
}
}
}
// State is a function primarily meant for testing usage; it is explicitly not
// part of the TaskEngine interface and should not be relied upon.
// It returns an internal representation of the state of this DockerTaskEngine.
func (engine *DockerTaskEngine) State() *dockerstate.DockerTaskEngineState {
return engine.state
}
// Capabilities returns the supported capabilities of this agent / docker-client pair.
// Currently, the following capabilities are possible:
//
// com.amazonaws.ecs.capability.privileged-container
// com.amazonaws.ecs.capability.docker-remote-api.1.17
// com.amazonaws.ecs.capability.docker-remote-api.1.18
// com.amazonaws.ecs.capability.docker-remote-api.1.19
// com.amazonaws.ecs.capability.docker-remote-api.1.20
// com.amazonaws.ecs.capability.logging-driver.json-file
// com.amazonaws.ecs.capability.logging-driver.syslog
// com.amazonaws.ecs.capability.logging-driver.fluentd
// com.amazonaws.ecs.capability.logging-driver.journald
// com.amazonaws.ecs.capability.logging-driver.gelf
// com.amazonaws.ecs.capability.selinux
// com.amazonaws.ecs.capability.apparmor
func (engine *DockerTaskEngine) Capabilities() []string {
err := engine.initDockerClient()
if err != nil {
return nil
}
capabilities := []string{}
if !engine.cfg.PrivilegedDisabled {
capabilities = append(capabilities, capabilityPrefix+"privileged-container")
}
versions := make(map[dockerclient.DockerVersion]bool)
for _, version := range engine.client.SupportedVersions() {
capabilities = append(capabilities, capabilityPrefix+"docker-remote-api."+string(version))
versions[version] = true
}
for _, loggingDriver := range engine.cfg.AvailableLoggingDrivers {
requiredVersion := dockerclient.LoggingDriverMinimumVersion[loggingDriver]
if _, ok := versions[requiredVersion]; ok {
capabilities = append(capabilities, capabilityPrefix+"logging-driver."+string(loggingDriver))
}
}
if engine.cfg.SELinuxCapable {
capabilities = append(capabilities, capabilityPrefix+"selinux")
}
if engine.cfg.AppArmorCapable {
capabilities = append(capabilities, capabilityPrefix+"apparmor")
}
return capabilities
}
// Version returns the underlying docker version.
func (engine *DockerTaskEngine) Version() (string, error) {
// Must be able to be called before Init()
err := engine.initDockerClient()
if err != nil {
return "", err
}
return engine.client.Version()
}