# Buggy code
def start_container(self, container, use_network_aliases=True):
    self.connect_container_to_networks(container, use_network_aliases)
    try:
        container.start()
    except APIError as ex:
        if "driver failed programming external connectivity" in ex.explanation:
            log.warn("Host is already in use by another container")
        raise OperationFailedError(
            "Cannot start service %s: %s" % (self.name, ex.explanation)
        )
    return container


# Traceback (requests.exceptions.HTTPError)
$ docker-compose -f badcompose.yaml  up
Creating ddev-d8composer-db ... done
Creating ddev-d8composer-dba ...
Creating ddev-d8composer-web ...
Creating ddev-d8composer-dba ... done
ERROR: for ddev-d8composer-web  a bytes-like object is required, not 'str'

ERROR: for web  a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "site-packages/docker/api/client.py", line 261, in _raise_for_status
File "site-packages/requests/models.py", line 940, in raise_for_status
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.36/containers/5154c7d2e17e152a31a3513dad4e4354a4a57ba514b83382faff45eec9bb85d1/start

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "compose/service.py", line 625, in start_container
File "compose/container.py", line 241, in start
File "site-packages/docker/utils/decorators.py", line 19, in wrapped
File "site-packages/docker/api/container.py", line 1095, in start
File "site-packages/docker/api/client.py", line 263, in _raise_for_status
File "site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Ports are not available: /forwards/expose/port returned unexpected status: 500'")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 1106, in up
File "compose/cli/main.py", line 1102, in up
File "compose/project.py", line 570, in up
File "compose/parallel.py", line 112, in parallel_execute
File "compose/parallel.py", line 210, in producer
File "compose/project.py", line 556, in do
File "compose/service.py", line 546, in execute_convergence_plan
File "compose/service.py", line 467, in _execute_convergence_create
File "compose/parallel.py", line 112, in parallel_execute
File "compose/parallel.py", line 210, in producer
File "compose/service.py", line 465, in <lambda>
File "compose/service.py", line 457, in create_and_start
File "compose/service.py", line 627, in start_container
TypeError: a bytes-like object is required, not 'str'
[87400] Failed to execute script docker-compose

# Fixed code
def start_container(self, container, use_network_aliases=True):
    self.connect_container_to_networks(container, use_network_aliases)
    try:
        container.start()
    except APIError as ex:
        expl = binarystr_to_unicode(ex.explanation)
        if "driver failed programming external connectivity" in expl:
            log.warn("Host is already in use by another container")
        raise OperationFailedError("Cannot start service %s: %s" % (self.name, expl))
    return container