agent/api/task/task.go
func (task *Task) initializeDockerVolumes(sharedVolumeMatchFullConfig bool, dockerClient dockerapi.DockerClient, ctx context.Context) error {
	for i, vol := range task.Volumes {
		// No need to do this for non-docker volume, eg: host bind/empty volume
		if vol.Type != DockerVolumeType {
			continue
		}

		dockerVolume, ok := vol.Volume.(*taskresourcevolume.DockerVolumeConfig)
		if !ok {
			return errors.New("task volume: volume configuration does not match the type 'docker'")
		}
		// Agent needs to create task-scoped volume
		if dockerVolume.Scope == taskresourcevolume.TaskScope {
			err := task.addTaskScopedVolumes(ctx, dockerClient, &task.Volumes[i])
			if err != nil {
				return err
			}
		} else {
			// Agent needs to create shared volume if that's auto provisioned
			err := task.addSharedVolumes(sharedVolumeMatchFullConfig, ctx, dockerClient, &task.Volumes[i])
			if err != nil {
				return err
			}
		}
	}
	return nil
}
func (task *Task) initializeDockerVolumes(sharedVolumeMatchFullConfig bool, dockerClient dockerapi.DockerClient, ctx context.Context) error {
	for i, vol := range task.Volumes {
		// No need to do this for non-docker volume, eg: host bind/empty volume
		if vol.Type != DockerVolumeType {
			continue
		}

		dockerVolume, ok := vol.Volume.(*taskresourcevolume.DockerVolumeConfig)
		if !ok {
			return errors.New("task volume: volume configuration does not match the type 'docker'")
		}
		// Agent needs to create task-scoped volume
		if dockerVolume.Scope == taskresourcevolume.TaskScope {
			err := task.addTaskScopedVolumes(ctx, dockerClient, &task.Volumes[i])
			if err != nil {
				return err
			}
		} else {
			// Agent needs to create shared volume if that's auto provisioned
			err := task.addSharedVolumes(sharedVolumeMatchFullConfig, ctx, dockerClient, &task.Volumes[i])
			if err != nil {
				return err
			}
		}
	}
	return nil
}
// initializeDockerVolumes checks the volume resource in the task to determine if the agent
// should create the volume before creating the container