On the last days I've been playing with WildFly Swarm and I decided to deploy a simple app with Docker. Should work fine, at least that was what I thought. Built a container with the following Dockerfile and instead of a working web app, all that I got was the error java.net.SocketException: Protocol family unavailable.

FROM java:openjdk-8-jdk

COPY target/issues.jar /opt/issues.jar


CMD ["java","-jar","/opt/issues.jar"]

For some reason, WildFly and Java decided to use the IPv6 network interface from Docker instead the v4, so all you have to do is tell Java to prefer IPv4 instead with the following configuration option in your pom.xml file inside your WildFly plugin.


        <!-- ADD THIS -->

Another way to solve is adding the same properties to the run command at the Dockerfile, so you choose where you'll add it. Bellow the Dockerfile solution.

FROM java:openjdk-8-jdk
ENV JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"

COPY target/issues.jar /opt/issues.jar


ENTRYPOINT exec java $JAVA_OPTS -jar /opt/issues.jar