Repository: localstack/localstack

Issue:
bug: incorrect docker cmd result unwrapping
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

**Given**: a setup with `podman` forwarding socket to the host; `localstack` connecting to `unix:///tmp/podman.sock`, as suggested by the documentation.

**What's wrong**: an attempt to fire `localstack start` dies with `TypeError: list indices must be integers or slices, not str`, because the string result of a docker command execution is checked for validity incorrectly.

See full stacktrace:

```
Traceback (most recent call last):
  File "/opt/homebrew/bin/localstack", line 23, in <module>
    main()
  File "/opt/homebrew/bin/localstack", line 19, in main
    main.main()
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/cli/main.py", line 6, in main
    cli()
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/cli/plugin.py", line 15, in __call__
    self.group(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/utils/analytics/cli.py", line 66, in publisher_wrapper
    return fn(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/cli/localstack.py", line 148, in cmd_start
    bootstrap.start_infra_in_docker()
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/utils/bootstrap.py", line 683, in start_infra_in_docker
    prepare_docker_start()
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/utils/bootstrap.py", line 582, in prepare_docker_start
    if DOCKER_CLIENT.is_container_running(container_name):
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/utils/container_utils/container_client.py", line 446, in is_container_running
    return container_name in self.get_running_container_names()
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/utils/container_utils/container_client.py", line 440, in get_running_container_names
    result = self.list_containers(all=False)
  File "/opt/homebrew/lib/python3.10/site-packages/localstack/utils/container_utils/docker_cmd_client.py", line 210, in list_containers
    "id": container["ID"],
TypeError: list indices must be integers or slices, not str
```

### Expected Behavior

No error raised.

### How are you starting LocalStack?

With the `localstack` script

### Steps To Reproduce

#### How are you starting localstack (e.g., `bin/localstack` command, arguments, or `docker-compose.yml`)

`DOCKER_CMD="podman" DOCKER_SOCK="/tmp/podman.sock" DOCKER_HOST="unix:///tmp/podman.sock" localstack start`

> As a prerequisite, an SSH tunnel to a `podman` machine is enabled.


### Environment

```markdown
- OS: MacOS, running aarch64 (M1 chip)
- LocalStack: CLI 0.14.5
```


### Anything else?

_No response_


Discussion:
Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our [Slack Community](https://localstack.cloud/contact/) for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our [contributing guidelines](https://github.com/localstack/.github/blob/main/CONTRIBUTING.md) and our [developer guide](https://docs.localstack.cloud/developer-guide/).
hi @artkonr , thanks for the report! we currently don't officially support podman, but will look into the issue nonetheless!
podman seems to be providing a format fully json compliant document (array), whereas docker provides a line with a json object per container. The code is working from the line by line case docker provides.

Resolving patch:
diff --git a/localstack/utils/container_utils/docker_cmd_client.py b/localstack/utils/container_utils/docker_cmd_client.py
--- a/localstack/utils/container_utils/docker_cmd_client.py
+++ b/localstack/utils/container_utils/docker_cmd_client.py
@@ -201,7 +201,10 @@ def list_containers(self, filter: Union[List[str], str, None] = None, all=True)
             ) from e
         container_list = []
         if cmd_result:
-            container_list = [json.loads(line) for line in cmd_result.splitlines()]
+            if cmd_result[0] == "[":
+                container_list = json.loads(cmd_result)
+            else:
+                container_list = [json.loads(line) for line in cmd_result.splitlines()]
         result = []
         for container in container_list:
             result.append(


Test patch: