Firestore 模拟器在 Docker 中运行时无法启动



我正在运行一个基于 alpine 的 docker 映像,该映像安装了nodejsopenjdk8。 通过 npm 成功安装 firebase-tools 并尝试使用以下命令启动 firestore 模拟器后:

firebase serve --only firestore

我收到以下错误:

    ⚠  firestore: Exception in thread "main"
    ⚠  firestore: java.io.IOException: Failed to bind
    ⚠  firestore:   at io.grpc.netty.NettyServer.start(NettyServer.java:256)
            at io.grpc.internal.ServerImpl.start(ServerImpl.java:167)
            at io.grpc.internal.ServerImpl.start(ServerImpl.java:81)
            at io.gapi.emulators.grpc.GrpcServer.start(GrpcServer.java:151)
            at com.google.cloud.datastore.emulator.firestore.CloudFirestore.main(CloudFirestore.java:69)
    Caused by: java.net.SocketException: Protocol family unavailable
            at sun.nio.ch.Net.bind0(Native Method)
            at sun.nio.ch.Net.bind(Net.java:433)
            at sun.nio.ch.Net.bind(Net.java:425)
            at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    ⚠  firestore:   at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130)
            at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562)
            at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1358)
            at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
            at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
            at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
            at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:258)
            at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366)
            at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    ⚠  firestore:   at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
            at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:474)
            at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909)
            at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
            at java.lang.Thread.run(Thread.java:748)

我尝试按如下方式设置JAVA_OPTS

export JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"

但我仍然收到类似的错误:

    ⚠  firestore: Exception in thread "main"
    ⚠  firestore: java.io.IOException: Failed to bind
            at io.grpc.netty.NettyServer.start(NettyServer.java:256)
            at io.grpc.internal.ServerImpl.start(ServerImpl.java:167)
            at io.grpc.internal.ServerImpl.start(ServerImpl.java:81)
            at io.gapi.emulators.grpc.GrpcServer.start(GrpcServer.java:151)
            at com.google.cloud.datastore.emulator.firestore.CloudFirestore.main(CloudFirestore.java:69)
    Caused by: java.net.SocketException: Protocol family unavailable
            at sun.nio.ch.Net.bind0(Native Method)
            at sun.nio.ch.Net.bind(Net.java:433)
            at sun.nio.ch.Net.bind(Net.java:425)
            at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
            at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130)
            at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562)
            at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1358)
            at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
            at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
            at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
            at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:258)
            at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366)
            at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
            at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
            at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:474)
            at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909)
            at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
            at java.lang.Thread.run(Thread.java:748)

有没有人看到此错误并找到解决方案?

解决方案很简单,尽管我必须承认没有多大意义,而是直接运行 JAR,而不是通过 firebase 工具启动它。

java -jar $HOME/.cache/firebase/emulators/cloud-firestore-emulator-v1.3.0.jar --host=127.0.0.1

它是否试图绑定到 IPV6 地址?要与带有 IPV4 和谷歌云 SDK 的自定义端口配合使用,请执行以下操作:

gcloud beta emulators firestore start --host-port=127.0.0.1:8772

否则,尝试在您的码头工人上启用IPV6?

相关内容

  • 没有找到相关文章

最新更新