在 MacOS 中 docker 上的 Wildfly Swarm

Wildfly Swarm on docker in MacOS

我正在尝试 运行 在 macOS Docker 中的 Wildfly Swarm 服务,但它抛出异常。我不知道是 MacOS 问题(我相信是)还是 JVM 问题。

我正在为 wildly swarm 使用一个非常简单的 Docker 文件:

FROM java:openjdk-8-alpine

ADD target/service-swarm.jar /opt/service-swarm.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/opt/service-swarm.jar"]

我正在为我的服务使用最小 swarm + vaadin

这是 docker 日志:

2018-03-16 14:54:17,475 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service org.wildfly.undertow.listener.default: org.jboss.msc.service.StartException in service org.wildfly.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.
    at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:181)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
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 sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:179)
    at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:310)
    at org.wildfly.extension.undertow.HttpListenerService.startListening(HttpListenerService.java:106)
    at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:169)
    ... 5 more

2018-03-16 14:54:17,717 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "undertow"),
    ("server" => "default-server"),
    ("http-listener" => "default")
]) - failure description: {"WFLYCTL0080: Failed services" => {"org.wildfly.undertow.listener.default" => "WFLYUT0082: Could not start 'default' listener.
    Caused by: java.net.SocketException: Protocol family unavailable"}}
2018-03-16 14:54:17,774 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service org.wildfly.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.

2018-03-16 14:54:17,820 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
2018-03-16 14:54:17,828 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Swarm 2018.3.3 (WildFly Core 3.0.8.Final) started (with errors) in 2732ms - Started 82 of 92 services (1 services failed or missing dependencies, 17 services are lazy, passive or on-demand)
2018-03-16 14:54:17,859 ERROR [stderr] (main) java.lang.RuntimeException: org.jboss.msc.service.StartException in service org.wildfly.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.
2018-03-16 14:54:17,860 ERROR [stderr] (main)   at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:45)
2018-03-16 14:54:17,860 ERROR [stderr] (main)   at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.bootstrap(ServerBootstrapImpl.java:113)
2018-03-16 14:54:17,860 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.start(Swarm.java:398)
2018-03-16 14:54:17,861 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.main(Swarm.java:742)
2018-03-16 14:54:17,861 ERROR [stderr] (main)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-03-16 14:54:17,861 ERROR [stderr] (main)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-03-16 14:54:17,862 ERROR [stderr] (main)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-03-16 14:54:17,862 ERROR [stderr] (main)   at java.lang.reflect.Method.invoke(Method.java:498)
2018-03-16 14:54:17,862 ERROR [stderr] (main)   at org.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:53)
2018-03-16 14:54:17,862 ERROR [stderr] (main)   at org.wildfly.swarm.bootstrap.Main.run(Main.java:132)
2018-03-16 14:54:17,862 ERROR [stderr] (main)   at org.wildfly.swarm.bootstrap.Main.main(Main.java:85)
2018-03-16 14:54:17,863 ERROR [stderr] (main) Caused by: org.jboss.msc.service.StartException in service org.wildfly.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.
2018-03-16 14:54:17,863 ERROR [stderr] (main)   at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:181)
2018-03-16 14:54:17,863 ERROR [stderr] (main)   at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
2018-03-16 14:54:17,863 ERROR [stderr] (main)   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
2018-03-16 14:54:17,863 ERROR [stderr] (main)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2018-03-16 14:54:17,863 ERROR [stderr] (main)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2018-03-16 14:54:17,864 ERROR [stderr] (main)   at java.lang.Thread.run(Thread.java:745)
2018-03-16 14:54:17,864 ERROR [stderr] (main) Caused by: java.net.SocketException: Protocol family unavailable
2018-03-16 14:54:17,864 ERROR [stderr] (main)   at sun.nio.ch.Net.bind0(Native Method)
2018-03-16 14:54:17,864 ERROR [stderr] (main)   at sun.nio.ch.Net.bind(Net.java:433)
2018-03-16 14:54:17,865 ERROR [stderr] (main)   at sun.nio.ch.Net.bind(Net.java:425)
2018-03-16 14:54:17,865 ERROR [stderr] (main)   at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
2018-03-16 14:54:17,865 ERROR [stderr] (main)   at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
2018-03-16 14:54:17,865 ERROR [stderr] (main)   at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:179)
2018-03-16 14:54:17,865 ERROR [stderr] (main)   at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:310)
2018-03-16 14:54:17,866 ERROR [stderr] (main)   at org.wildfly.extension.undertow.HttpListenerService.startListening(HttpListenerService.java:106)
2018-03-16 14:54:17,866 ERROR [stderr] (main)   at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:169)
2018-03-16 14:54:17,866 ERROR [stderr] (main)   ... 5 more
2018-03-16 14:54:17,866 ERROR [stderr] (main) java.lang.RuntimeException: org.jboss.msc.service.StartException in service org.wildfly.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.
2018-03-16 14:54:17,866 ERROR [stderr] (main)   at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:45)
2018-03-16 14:54:17,867 ERROR [stderr] (main)   at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.bootstrap(ServerBootstrapImpl.java:113)
2018-03-16 14:54:17,867 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.start(Swarm.java:398)
2018-03-16 14:54:17,867 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.main(Swarm.java:742)
2018-03-16 14:54:17,867 ERROR [stderr] (main)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-03-16 14:54:17,867 ERROR [stderr] (main)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-03-16 14:54:17,867 ERROR [stderr] (main)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-03-16 14:54:17,868 ERROR [stderr] (main)   at java.lang.reflect.Method.invoke(Method.java:498)
2018-03-16 14:54:17,868 ERROR [stderr] (main)   at org.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:53)
2018-03-16 14:54:17,868 ERROR [stderr] (main)   at org.wildfly.swarm.bootstrap.Main.run(Main.java:132)
2018-03-16 14:54:17,876 ERROR [stderr] (main)   at org.wildfly.swarm.bootstrap.Main.main(Main.java:85)
2018-03-16 14:54:17,876 ERROR [stderr] (main) Caused by: org.jboss.msc.service.StartException in service org.wildfly.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.
2018-03-16 14:54:17,876 ERROR [stderr] (main)   at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:181)
2018-03-16 14:54:17,876 ERROR [stderr] (main)   at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
2018-03-16 14:54:17,877 ERROR [stderr] (main)   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
2018-03-16 14:54:17,877 ERROR [stderr] (main)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2018-03-16 14:54:17,877 ERROR [stderr] (main)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2018-03-16 14:54:17,877 ERROR [stderr] (main)   at java.lang.Thread.run(Thread.java:745)
2018-03-16 14:54:17,878 ERROR [stderr] (main) Caused by: java.net.SocketException: Protocol family unavailable
2018-03-16 14:54:17,878 ERROR [stderr] (main)   at sun.nio.ch.Net.bind0(Native Method)
2018-03-16 14:54:17,878 ERROR [stderr] (main)   at sun.nio.ch.Net.bind(Net.java:433)
2018-03-16 14:54:17,878 ERROR [stderr] (main)   at sun.nio.ch.Net.bind(Net.java:425)
2018-03-16 14:54:17,879 ERROR [stderr] (main)   at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
2018-03-16 14:54:17,879 ERROR [stderr] (main)   at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
2018-03-16 14:54:17,879 ERROR [stderr] (main)   at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:179)
2018-03-16 14:54:17,879 ERROR [stderr] (main)   at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:310)
2018-03-16 14:54:17,879 ERROR [stderr] (main)   at org.wildfly.extension.undertow.HttpListenerService.startListening(HttpListenerService.java:106)
2018-03-16 14:54:17,879 ERROR [stderr] (main)   at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:169)
2018-03-16 14:54:17,880 ERROR [stderr] (main)   ... 5 more
2018-03-16 14:54:17,881 INFO  [org.wildfly.swarm] (Thread-2) WFSWARM0027: Shutdown requested

这是 MacOS 问题,还是 docker + wildly-swarm 问题?我该如何解决?

这是 Docker 内 IPv6 寻址的一个已知问题。要解决它,您需要在 WF Swarm 插件上设置 属性 以优先使用 IPv4 寻址。参见 https://github.com/wildfly-swarm/wildfly-swarm-examples/blob/master/ribbon/pom.xml#L33