agent/engine/dockerstate/docker_task_engine_state.go
func (state *DockerTaskEngineState) AddContainer(container *apicontainer.DockerContainer, task *apitask.Task) {
	state.lock.Lock()
	defer state.lock.Unlock()
	if task == nil || container == nil {
		log.Crit("Addcontainer called with nil task/container")
		return
	}

	_, exists := state.tasks[task.Arn]
	if !exists {
		log.Debug("AddContainer called with unknown task; adding", "arn", task.Arn)
		state.tasks[task.Arn] = task
	}

	state.storeIDToContainerTaskUnsafe(container, task)

	dockerID := container.DockerID
	v3EndpointID := container.Container.V3EndpointID
	// stores the v3EndpointID mappings only if container's dockerID exists and container's v3EndpointID has been generated
	if dockerID != "" && v3EndpointID != "" {
		state.storeV3EndpointIDToTaskUnsafe(v3EndpointID, task.Arn)
		state.storeV3EndpointIDToDockerIDUnsafe(v3EndpointID, dockerID)
	}

	existingMap, exists := state.taskToID[task.Arn]
	if !exists {
		existingMap = make(map[string]*apicontainer.DockerContainer, len(task.Containers))
		state.taskToID[task.Arn] = existingMap
	}
	existingMap[container.Container.Name] = container
}
func (state *DockerTaskEngineState) AddContainer(container *apicontainer.DockerContainer, task *apitask.Task) {
	state.lock.Lock()
	defer state.lock.Unlock()
	if task == nil || container == nil {
		log.Crit("Addcontainer called with nil task/container")
		return
	}

	_, exists := state.tasks[task.Arn]
	if !exists {
		log.Debug("AddContainer called with unknown task; adding", "arn", task.Arn)
		state.tasks[task.Arn] = task
	}

	state.storeIDToContainerTaskUnsafe(container, task)

	dockerID := container.DockerID
	v3EndpointID := container.Container.V3EndpointID
	// stores the v3EndpointID mappings only if container's dockerID exists and container's v3EndpointID has been generated
	if dockerID != "" && v3EndpointID != "" {
		state.storeV3EndpointIDToTaskUnsafe(v3EndpointID, task.Arn)
		state.storeV3EndpointIDToDockerIDUnsafe(v3EndpointID, dockerID)
	}

	existingMap, exists := state.taskToID[task.Arn]
	if !exists {
		existingMap = make(map[string]*apicontainer.DockerContainer, len(task.Containers))
		state.taskToID[task.Arn] = existingMap
	}
	existingMap[container.Container.Name] = container
}
// AddContainer adds a container to the state.
// If the container has been added with only a name and no docker-id, this
// updates the state to include the docker id