diff --git a/moto/s3/responses.py b/moto/s3/responses.py index fb1735a5c..6abb4f2d1 100755 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -55,8 +55,10 @@ class ResponseObject(_TemplateEnvironmentMixin): if not host: host = urlparse(request.url).netloc - if not host or host.startswith("localhost") or re.match(r"^[^.]+$", host): - # For localhost or local domain names, default to path-based buckets + if (not host or host.startswith('localhost') or + re.match(r'^[^.]+$', host) or re.match(r'^.*\.svc\.cluster\.local$', host)): + # Default to path-based buckets for (1) localhost, (2) local host names that do not + # contain a "." (e.g., Docker container host names), or (3) kubernetes host names return False match = re.match(r'^([^\[\]:]+)(:\d+)?$', host)