docker · Docker
报错原文
Bind for 0.0.0.0:8080 failed: port is already allocated
这是什么意思
你用 -p 要占宿主机的那个端口,而它已经被另一个容器或进程占着。最常见的是之前不加 --rm 启动的容器还留在那里(停着或跑着),或者 compose 还攥着一个旧容器。docker ps --filter publish=8080 会直接指出发布该端口的容器;如果其实是宿主机上的普通程序而不是容器,用 lsof -i :8080 找。只改宿主机一侧,比如 -p 8081:80,能让你先跑起来,但旧容器不清掉,下次还是同一场撞车。
怎么修
docker ps --filter publish=8080- 来自
- docker
- Docker
- 12
docker 的错误要先归到某一层才读得懂——客户端连不上守护进程、镜像仓库拒绝你、构建过程中某条 RUN 失败、容器一起来就死掉,是四种不同的问题——而在构建和运行这两层,那行字本身并不是原因:原因在里面那条命令留下的输出里,各层修复的代价也不一样。
怎么读报错
- 从第一行往下读。越往下越是工具内部的事,起因通常写在最上面。
- 有文件名和行号就从那里查——不是栈顶那一帧,而是最上面那条提到你自己写的文件的行。
- 把报错原文照样去搜,但先去掉你自己的路径和变量名,正是那些让搜索匹配不上。
- 同一种情况在不同版本里措辞不同。结果不对头,就把版本号一起加进查询。
- 粘贴修法之前,先确认它会丢掉什么。这里面有些是不能撤回的。
常见问题
Q. “Bind for 0.0.0.0:8080 failed: port is already allocated” 是什么意思?
你用 -p 要占宿主机的那个端口,而它已经被另一个容器或进程占着。最常见的是之前不加 --rm 启动的容器还留在那里(停着或跑着),或者 compose 还攥着一个旧容器。docker ps --filter publish=8080 会直接指出发布该端口的容器;如果其实是宿主机上的普通程序而不是容器,用 lsof -i :8080 找。只改宿主机一侧,比如 -p 8081:80,能让你先跑起来,但旧容器不清掉,下次还是同一场撞车。
Q. 怎么修?
docker ps --filter publish=8080 —— 执行前先看上面的说明,确认这条命令会丢掉什么。
Q. 这是哪个工具报的?
docker。它属于Docker,报错原文有 8 个词。
相关报错
Conflict. The container name "/api" is already in use by containerdockerOSError: [Errno 98] Address already in usepythonfailed to register layer: Error processing tar file(exit status 1): no space left on devicedockerpull access denied for myapp, repository does not exist or may require 'docker login'dockermanifest for myapp:v2 not found: manifest unknowndockerunauthorized: incorrect username or passworddockerfailed to solve: process "/bin/sh -c npm ci" did not complete successfully: exit code: 1buildkitCOPY failed: file not found in build context or excluded by .dockerignoredocker