首页 > 系统相关 >解决Windows下Docker启动容器时,端口被占用错误

解决Windows下Docker启动容器时,端口被占用错误

时间:2023-04-10 17:59:09浏览次数:45  
标签:netty java Windows 端口 springframework grpc io org Docker

今天在启动本机的nacos容器时报了如下错误:


         ,--.
       ,--.'|
   ,--,:  : |                                           Nacos 2.0.2
,`--.'`|  ' :                       ,---.               Running in stand alone mode, All function modules
|   :  :  | |                      '   ,'\   .--.--.    Port: 8848
:   |   \ | :  ,--.--.     ,---.  /   /   | /  /    '   Pid: 9384
|   : '  '; | /       \   /     \.   ; ,. :|  :  /`./   Console: http://192.168.0.241:8848/nacos/index.html
'   ' ;.    ;.--.  .-. | /    / ''   | |: :|  :  ;_
|   | | \   | \__\/: . ..    ' / '   | .; : \  \    `.      https://nacos.io
'   : |  ; .' ," .--.; |'   ; :__|   :    |  `----.   \
|   | '`--'  /  /  ,.  |'   | '.'|\   \  /  /  /`--'  /
'   : |     ;  :   .'   \   :    : `----'  '--'.     /
;   |.'     |  ,     .-./\   \  /            `--'---'
'---'        `--`---'     `----'

2023-04-10 17:20:44,253 INFO Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@251ebf23' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2023-04-10 17:20:44,259 INFO Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2023-04-10 17:20:45,654 INFO Tomcat initialized with port(s): 8848 (http)

2023-04-10 17:20:46,412 INFO Root WebApplicationContext: initialization completed in 8938 ms

2023-04-10 17:20:51,397 WARN There are no [com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent] publishers for this event, please register

2023-04-10 17:20:51,399 WARN There are no [com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent] publishers for this event, please register

2023-04-10 17:20:51,400 WARN There are no [com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent] publishers for this event, please register

2023-04-10 17:20:51,401 WARN There are no [com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent] publishers for this event, please register

2023-04-10 17:20:54,250 WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcSdkServer': Invocation of init method failed; nested exception is java.io.IOException: Failed to bind

2023-04-10 17:20:54,295 INFO Nacos Log files: D:\tools\nacos-server-2.0.2\nacos\logs

2023-04-10 17:20:54,296 INFO Nacos Log files: D:\tools\nacos-server-2.0.2\nacos\conf

2023-04-10 17:20:54,296 INFO Nacos Log files: D:\tools\nacos-server-2.0.2\nacos\data

2023-04-10 17:20:54,300 ERROR Startup errors :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcSdkServer': Invocation of init method failed; nested exception is java.io.IOException: Failed to bind
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:413)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1761)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
        at com.alibaba.nacos.Nacos.main(Nacos.java:35)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: java.io.IOException: Failed to bind
        at io.grpc.netty.shaded.io.grpc.netty.NettyServer.start(NettyServer.java:246)
        at io.grpc.internal.ServerImpl.start(ServerImpl.java:184)
        at io.grpc.internal.ServerImpl.start(ServerImpl.java:90)
        at com.alibaba.nacos.core.remote.grpc.BaseGrpcServer.startServer(BaseGrpcServer.java:152)
        at com.alibaba.nacos.core.remote.BaseRpcServer.start(BaseRpcServer.java:47)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
        ... 26 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:444)
        at sun.nio.ch.Net.bind(Net.java:436)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:225)
        at io.grpc.netty.shaded.io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:132)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:551)
        at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1345)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:503)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:488)
        at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:984)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannel.bind(AbstractChannel.java:247)
        at io.grpc.netty.shaded.io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:355)
        at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:416)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:515)
        at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
        at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)
2023-04-10 17:20:55,949 WARN [WatchFileCenter] start close

2023-04-10 17:20:55,950 WARN [WatchFileCenter] start to shutdown this watcher which is watch : D:\tools\nacos-server-2.0.2\nacos\data\tps

2023-04-10 17:20:55,950 WARN [WatchFileCenter] start to shutdown this watcher which is watch : D:\tools\nacos-server-2.0.2\nacos\conf

2023-04-10 17:20:55,950 WARN [WatchFileCenter] start to shutdown this watcher which is watch : D:\tools\nacos-server-2.0.2\nacos\data\loader

2023-04-10 17:20:55,950 WARN [WatchFileCenter] already closed

2023-04-10 17:20:55,950 WARN [NotifyCenter] Start destroying Publisher

2023-04-10 17:20:55,951 WARN [NotifyCenter] Destruction of the end

2023-04-10 17:20:55,951 ERROR Nacos failed to start, please see D:\tools\nacos-server-2.0.2\nacos\logs\nacos.log for more details.

2023-04-10 17:20:55,959 INFO

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2023-04-10 17:20:55,960 ERROR Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcSdkServer': Invocation of init method failed; nested exception is java.io.IOException: Failed to bind
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:413)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1761)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
        at com.alibaba.nacos.Nacos.main(Nacos.java:35)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: java.io.IOException: Failed to bind
        at io.grpc.netty.shaded.io.grpc.netty.NettyServer.start(NettyServer.java:246)
        at io.grpc.internal.ServerImpl.start(ServerImpl.java:184)
        at io.grpc.internal.ServerImpl.start(ServerImpl.java:90)
        at com.alibaba.nacos.core.remote.grpc.BaseGrpcServer.startServer(BaseGrpcServer.java:152)
        at com.alibaba.nacos.core.remote.BaseRpcServer.start(BaseRpcServer.java:47)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
        ... 26 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:444)
        at sun.nio.ch.Net.bind(Net.java:436)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:225)
        at io.grpc.netty.shaded.io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:132)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:551)
        at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1345)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:503)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:488)
        at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:984)
        at io.grpc.netty.shaded.io.netty.channel.AbstractChannel.bind(AbstractChannel.java:247)
        at io.grpc.netty.shaded.io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:355)
        at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:416)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:515)
        at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
        at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)

我的环境信息

Windows版本: Windows 11 专业版  版本 22H2
Docker version 20.10.23, build 7155243
启用Hyper-V 和 WSL2

查找问题

首选确保本机端口是否被占用,使用如下命令:

netstat -ano | findstr 8488

结果端口没有被占用

查资料之后发现 Hyper-V 会保留部分tcp端口,开始到结束范围内的端口不可用, 使用如下命令查看保留的端口:

netsh interface ipv4 show excludedportrange protocol=tcp

可以得到

解决办法

此时可以修改容器启动命令(主要是修改端口)重新启动容器。

这种是绕过了被保留的端口, 如果你的程序一定要使用范围内的端口,有如下三种方式

一、临时关闭Hyper-V

  1. 临时关闭Hyper-V

  2. 配置端口

  3. 恢复Hyper-V

二、重启电脑大法

保留的端口是随机的,每次重启电脑都会改变,因此可以通过重启电脑来解决。

三、永久排除保留端口

  • 在运行 Docker 之前,以管理员身份运行 powershell

  • 使用以下命令永久排除6379作为保留端口(如果端口被占用需要重启一次电脑)

netsh int ipv4 add excludedportrange protocol=tcp startport=8848 numberofports=1 store=persistent
netsh int ipv4 add excludedportrange protocol=tcp startport=9848 numberofports=1 store=persistent
netsh int ipv4 add excludedportrange protocol=tcp startport=9849 numberofports=1 store=persistent

提示:关键在于store=persistent参数表示持久化信息
上面的命令可以通过修改numberofports参数保留startport开始的多个端口

  • 再次运行 netsh interface ipv4 show excludedportrange protocol=tcp 命令可以看到6379端口已被排除(带有*号标记)

之后再重启电脑8848 9848 9849端口就不会包含在保留端口内了。

总结

三种解决方法中,第一种临时关闭Hyper-V可以避免重启电脑,可以作为紧急解决办法。第二种重启电脑需要靠运气,第三种永久排除保留端口是最高效的。

标签:netty,java,Windows,端口,springframework,grpc,io,org,Docker
From: https://www.cnblogs.com/fuqian/p/17303729.html

相关文章

  • Docker的网络模式
    1、Docker网络实现原理(1)Docker使用Linux桥接,在宿主机虚拟一个Docker容器网桥(docker0),Docker启动一个容器时会根据Docker网桥的网段分配给容器一个IP地址,称为Container-IP,同时Docker网桥是每个容器的默认网关。因为在同一宿主机内的容器都接入同一个网桥,这样容器之间就能够通过容器......
  • odoo Docker Compose 部署
    1.docker-compose.yml配置version:'3.1'services:web: image:odoo:14 depends_on: -mydb ports: -"8069:8069" environment: -HOST=mydb -USER=odoo -PASSWORD=myodoo volumes: -odoo-web-data:/var/lib/odoo -./config......
  • ChatGPT垂直行业私有数据知识库向量数据库-Linux Ubuntu下安装docker-并且安装运行qdr
    现在基于GPT相应实现自建本地知识库,必不可少的就是向量数据库,现在介绍下qdrant向量数据库的安装。因为qdrant向量数据库只支持docker部署,所以在服务器上安装一下docker,下面是在ubutnu下安装dockeraptupdateaptinstallapt-transport-httpsca-certificatescurlgnupglsb-r......
  • 【解决】Windows10如何限制CPU最大使用率?
    【问题】Windows10如何限制CPU最大使用率?【解决】:进入控制面板→电源选项→更改计划设置→更改高级电源设置→处理器电源管理,最大处理器状态。设置需要的百分比即可。  ......
  • Windows 下安装 MySQL 8/7(使用命令行)
    下载Mysql的zip安装包下载地址:https://mirrors.aliyun.com/mysql/MySQL-8.0/https://mirrors.163.com/mysql/Downloads/MySQL-8.0/https://mirrors.aliyun.com/mysql/MySQL-5.7/https://mirrors.163.com/mysql/Downloads/MySQL-5.7/创建my.ini配置文件文件解压,进入mysql......
  • docker环境下安装zabbix
    一:安装docker安装部署docker.sh####################################脚本docker安装BEGINS[root@zabbix-agentyidong]#cat*.sh#!/bin/bashcat<<EOF1.安装docker2.启动docker3.退出EOFread-p"请选择一个变量来定位:"Selectcase$Selectin1)echo"安装docker软件开始--------......
  • Docker容器执行su命令报错su: cannot open session: Permission denied 解决方法
    1、先检查su命令权限是否正确,执行如下命令ll/etc/pam.d/su如果现实如图,则说明权限方面没问题,若您的执行结果与我的不一样,需调整权限。[root@blog-tag-gg~]#ll/etc/pam.d/su-rw-r--r--1rootroot5402月32021/etc/pam.d/su2、执行如下命令将如下。将su文......
  • failed to solve with frontend dockerfile.v0
    问题描述didi@didis-MacBook-Proipmi_exporter%dockerbuild-tipmi_exporter:0.1.[+]Building0.1s(1/2)=>[internal]loadbuil......
  • 【Windows开发】使用Windows官方版FUSE开发文件系统
    本文仅分析技术信息,不提供代码!1.用户态实现文件系统1.Linux上要自主实现文件系统一般会采用fuse,主要是能在用户态进程直接开发实现,不需要开发内核驱动模块,这部分官方示例代码和开源代码太多了,也没什么好讲的,另外MAC上也有fuse开源项目。2.Windows也有开源项目dokany,再加上其......
  • .NET6通过Docker搭建Nuget私有包服务器
    一、创建挂载目录文件夹1、可自定义文件夹路径,若提示文件夹不存在,就一级一级创建mkdir/usr/home/nuget/dbmkdir/usr/home/nuget/packages2、指定目录写入权限chmod666/usr/home/nuget二、sunside/simple-nuget-server容器1、创建容器sudodockerrun-d-p8085......