# Buggy code
def create_container(
    self,
    one_off=False,
    insecure_registry=False,
    do_build=True,
    intermediate_container=None,
    **override_options,
):
    """
    Create a container for this service. If the image doesn't exist, attempt to pull
    it.
    """
    container_options = self._get_container_create_options(
        override_options,
        one_off=one_off,
        intermediate_container=intermediate_container,
    )

    if do_build and self.can_be_built() and not self.client.images(name=self.full_name):
        self.build()

    try:
        return Container.create(self.client, **container_options)
    except APIError as e:
        if (
            e.response.status_code == 404
            and e.explanation
            and "No such image" in str(e.explanation)
        ):
            log.info("Pulling image %s..." % container_options["image"])
            output = self.client.pull(
                container_options["image"],
                stream=True,
                insecure_registry=insecure_registry,
            )
            stream_output(output, sys.stdout)
            return Container.create(self.client, **container_options)
        raise


# Traceback (compose.progress_stream.StreamOutputError)
Pulling image 50ff1e85c429:latest...
Pulling repository 50ff1e85c429
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.main", line 31, in main
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.docopt_command", line 21, in sys_dispatch
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.command", line 27, in dispatch
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.docopt_command", line 24, in dispatch
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.command", line 59, in perform_command
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.main", line 445, in up
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.project", line 183, in up
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.service", line 258, in recreate_containers
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.service", line 243, in create_container
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.progress_stream", line 37, in stream_output
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.progress_stream", line 50, in print_output_event
compose.progress_stream.StreamOutputError: Error: image library/50ff1e85c429:latest not found

# Fixed code
def create_container(
    self,
    one_off=False,
    insecure_registry=False,
    do_build=True,
    intermediate_container=None,
    **override_options,
):
    """
    Create a container for this service. If the image doesn't exist, attempt to pull
    it.
    """
    container_options = self._get_container_create_options(
        override_options,
        one_off=one_off,
        intermediate_container=intermediate_container,
    )

    if do_build and self.can_be_built() and not self.client.images(name=self.full_name):
        self.build()

    try:
        return Container.create(self.client, **container_options)
    except APIError as e:
        if (
            e.response.status_code == 404
            and e.explanation
            and "No such image" in str(e.explanation)
        ):
            self.pull(insecure_registry=insecure_registry)
            return Container.create(self.client, **container_options)
        raise