You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LocalStack默认端口53冲突,如何修改端口解决问题?

问题描述

最近开始使用localstack(版本2.3.1),运行localstack start -d时遇到端口冲突错误,具体报错如下:

> localstack start -d                 

     __                     _______ __             __
    / /   ____  _________ _/ / ___// /_____ ______/ /__
   / /   / __ \___/ __ `/ /\__ \__/ __ `/ ___/ //_/
  / /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
 /_____/\____/\___/__,_/_//____/\__/\__,_/\___/_/|_|

 💻 LocalStack CLI 2.3.1

[22:38:49] starting LocalStack in Docker mode 🐳               localstack.py:495
           preparing environment                               bootstrap.py:1197
           configuring container                               bootstrap.py:1205
2023-10-03T22:38:49.655  WARN --- [  MainThread] l.utils.docker_utils       : Unexpected error when attempting to determine container port status: ('Docker process returned with errorcode 125', b'', b'docker: Error response from daemon: driver failed programming external connectivity on endpoint focused_hawking (971564b7717a66fa84babce1ba3988c842735ffbeb1ba88c0a6560892cf75c27): Error starting userland proxy: listen tcp4 0.0.0.0:53: bind: address already in use.\n')
           starting container                                  bootstrap.py:1215
[22:38:51] detaching  

经排查,端口53被systemd-resolve占用,查询结果如下:

> sudo lsof -i :53  

[sudo] password for benyamin: 
COMMAND    PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 1226 systemd-resolve   13u  IPv4  28249      0t0  UDP 127.0.0.53:domain 
systemd-r 1226 systemd-resolve   14u  IPv4  28250      0t0  TCP 127.0.0.53:domain (LISTEN)

需要修改localstack的默认端口来解决该冲突(操作系统:Ubuntu 22.04)。

解决方法

LocalStack默认会将DNS服务的53端口映射到主机,可通过以下方式修改端口映射:

方式一:启动命令直接指定端口

启动时添加-p参数,将容器内的53端口映射到主机的空闲端口(示例用5353):

localstack start -d -p 5353:53/tcp -p 5353:53/udp

方式二:通过环境变量配置

临时生效:设置LOCALSTACK_DNS_PORT环境变量后启动:

LOCALSTACK_DNS_PORT=5353 localstack start -d

永久生效:将配置添加到LocalStack的用户配置文件~/.localstack/config中:

[localstack]
dns_port = 5353

方式三:修改自定义Docker Compose配置

如果使用自定义Docker Compose文件运行LocalStack,修改ports段的端口映射:

services:
  localstack:
    ...
    ports:
      - "5353:53/tcp"
      - "5353:53/udp"
      ...

内容的提问来源于stack exchange,提问作者Benyamin Jafari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 08:17:27