|
5 | 5 | from typing import List, Optional, Union
|
6 | 6 |
|
7 | 7 | from localstack import config
|
8 |
| -from localstack.constants import DEFAULT_VOLUME_DIR, DOCKER_IMAGE_NAME |
| 8 | +from localstack.constants import DEFAULT_VOLUME_DIR |
9 | 9 | from localstack.utils.collections import ensure_list
|
10 | 10 | from localstack.utils.container_utils.container_client import (
|
11 | 11 | ContainerClient,
|
12 | 12 | PortMappings,
|
13 | 13 | VolumeInfo,
|
14 | 14 | )
|
15 | 15 | from localstack.utils.net import IntOrPort, Port, PortNotAvailableException, PortRange
|
16 |
| -from localstack.utils.objects import singleton_factory |
17 | 16 | from localstack.utils.strings import to_str
|
18 | 17 |
|
19 | 18 | LOG = logging.getLogger(__name__)
|
@@ -147,23 +146,22 @@ def container_ports_can_be_bound(
|
147 | 146 | port_mappings.add(port.port, port.port, protocol=port.protocol)
|
148 | 147 | try:
|
149 | 148 | result = DOCKER_CLIENT.run_container(
|
150 |
| - _get_ports_check_docker_image(), |
151 |
| - entrypoint="sh", |
152 |
| - command=["-c", "echo test123"], |
| 149 | + "bash", |
| 150 | + command=["echo", "test123"], |
153 | 151 | ports=port_mappings,
|
154 | 152 | remove=True,
|
155 | 153 | )
|
156 | 154 | except Exception as e:
|
157 |
| - if "port is already allocated" not in str(e) and "address already in use" not in str(e): |
| 155 | + if "address already in use" not in str(e): |
158 | 156 | LOG.warning(
|
159 |
| - "Unexpected error when attempting to determine container port status: %s", e |
| 157 | + "Unexpected error when attempting to determine container port status", exc_info=e |
160 | 158 | )
|
161 | 159 | return False
|
162 | 160 | # TODO(srw): sometimes the command output from the docker container is "None", particularly when this function is
|
163 | 161 | # invoked multiple times consecutively. Work out why.
|
164 | 162 | if to_str(result[0] or "").strip() != "test123":
|
165 | 163 | LOG.warning(
|
166 |
| - "Unexpected output when attempting to determine container port status: %s", result[0] |
| 164 | + "Unexpected output when attempting to determine container port status: %s", result |
167 | 165 | )
|
168 | 166 | return True
|
169 | 167 |
|
@@ -240,29 +238,4 @@ def _random_port():
|
240 | 238 | )
|
241 | 239 |
|
242 | 240 |
|
243 |
| -@singleton_factory |
244 |
| -def _get_ports_check_docker_image() -> str: |
245 |
| - """ |
246 |
| - Determine the Docker image to use for Docker port availability checks. |
247 |
| - Uses either PORTS_CHECK_DOCKER_IMAGE (if configured), or otherwise inspects the running container's image. |
248 |
| - """ |
249 |
| - if config.PORTS_CHECK_DOCKER_IMAGE: |
250 |
| - # explicit configuration takes precedence |
251 |
| - return config.PORTS_CHECK_DOCKER_IMAGE |
252 |
| - if not config.is_in_docker: |
253 |
| - # local import to prevent circular imports |
254 |
| - from localstack.utils.bootstrap import get_docker_image_to_start |
255 |
| - |
256 |
| - # Use whatever image the user is trying to run LocalStack with, since they either have |
257 |
| - # it already, or need it by definition to start LocalStack. |
258 |
| - return get_docker_image_to_start() |
259 |
| - try: |
260 |
| - # inspect the running container to determine the image |
261 |
| - container = DOCKER_CLIENT.inspect_container(get_current_container_id()) |
262 |
| - return container["Config"]["Image"] |
263 |
| - except Exception: |
264 |
| - # fall back to using the default Docker image |
265 |
| - return DOCKER_IMAGE_NAME |
266 |
| - |
267 |
| - |
268 | 241 | DOCKER_CLIENT: ContainerClient = create_docker_client()
|
0 commit comments