1
votes

I'm trying to use the nifi with the docker, but to no avail. I have the following docker-file

version: "3.7"
services:
  nifi_one:
    image: apache/nifi
    hostname: nifi_one
    container_name: nifi_one
    environment:
      NIFI_WEB_HTTP_HOST: "http://localhost"
      NIFI_WEB_HTTP_PORT: "8084"
      NIFI_CLUSTER_IS_NODE: "true"
      NIFI_CLUSTER_NODE_PROTOCOL_PORT: "8085"
      NIFI_ZK_CONNECT_STRING: "localhost:2181"
      NIFI_ELECTION_MAX_WAIT: "1 min"
    network_mode: host
    volumes:
      - ./nifi:/nifi

  nifi_two:
    image: apache/nifi
    hostname: nifi_two
    container_name: nifi_two
    depends_on:
     - nifi_one
    environment:
      NIFI_WEB_HTTP_HOST: "http://localhost"
      NIFI_WEB_HTTP_PORT: "8084"
      NIFI_CLUSTER_IS_NODE: "true"
      NIFI_CLUSTER_NODE_PROTOCOL_PORT: "8085"
      NIFI_ZK_CONNECT_STRING: "localhost:2181"
      NIFI_ELECTION_MAX_WAIT: "1 min"
    network_mode: host
    volumes:
      - ./nifi:/nifi

volumes:
  nifi:

and i'm receiving this following error

2020-06-27 15:36:51,540 INFO [main] o.e.j.a.AnnotationConfiguration Scanning elapsed time=18ms 2020-06-27 15:36:51,542 INFO [main] o.e.j.server.handler.ContextHandler._ No Spring WebApplicationInitializer types detected on classpath 2020-06-27 15:36:51,684 INFO [main] o.e.jetty.server.handler.ContextHandler Started o.e.j.w.WebAppContext@51b35e4e{nifi-error,/,file:///opt/nifi/nifi-current/work/jetty/nifi-web-error-1.11.4.war/webapp/,AVAILABLE}{./work/nar/framework/nifi-framework-nar-1.11.4.nar-unpacked/NAR-INF/bundled-dependencies/nifi-web-error-1.11.4.war} 2020-06-27 15:36:51,922 WARN [main] org.apache.nifi.web.server.JettyServer Failed to start web server... shutting down. java.net.SocketException: Unresolved address at sun.nio.ch.Net.translateToSocketException(Net.java:131) at sun.nio.ch.Net.translateException(Net.java:157) at sun.nio.ch.Net.translateException(Net.java:163) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:87) at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:308) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:396) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.apache.nifi.web.server.JettyServer.start(JettyServer.java:952) at org.apache.nifi.NiFi.(NiFi.java:158) at org.apache.nifi.NiFi.(NiFi.java:72) at org.apache.nifi.NiFi.main(NiFi.java:301) Caused by: java.nio.channels.UnresolvedAddressException: null at sun.nio.ch.Net.checkAddress(Net.java:101) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:215) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:85) ... 11 common frames omitted 2020-06-27 15:36:51,923 INFO [Thread-1] org.apache.nifi.NiFi Initiating shutdown of Jetty web server... 2020-06-27 15:36:51,938 INFO [Thread-1] o.eclipse.jetty.server.AbstractConnector Stopped ServerConnector@cb03411{HTTP/1.1,[http/1.1]}{http://localhost:8084} 2020-06-27 15:36:51,938 INFO [Thread-1] org.eclipse.jetty.server.session node0 Stopped scavenging

Anyone could help me with this?

1

1 Answers

2
votes

Three changes need to be done to fix the problem (if you make only one change, other exceptions will be thrown):

  1. Remove the line NIFI_WEB_HTTP_HOST: "http://localhost" since it throws an exception while loading the webserver.
  2. The line NIFI_CLUSTER_IS_NODE: "true" should be changed to NIFI_CLUSTER_IS_NODE: "false" since no cluster is defined.
  3. Remove the line network_mode: host.

After making these changes, the two Nifi applications are loaded successfully.

However, one more definition is missing in the YAML file, which is essential to expose the Nifi applications to external access.
Adding the ports: definition enables fixing the external port in which the Nifi application listens to. The format is {external-port}:{internal-port}.

The YAML code below creates and loads two Nifi applications. One is exposed on http://localhost:8088/nifi, and the other on http://localhost:8090/nifi.

Note the definition of the shared folder that is shared between the three parties: the containers' host, nifi_one, and nifi_two.

The full definition is:

version: "2.0"
services:
  nifi_one:
    image: apache/nifi
    hostname: nifi_two
    container_name: nifi_one
    ports:
      - 8088:8080 # the internal port 8080 is exposed as 8088
    environment:
      NIFI_WEB_HTTP_PORT: "8080"
      NIFI_CLUSTER_IS_NODE: "false"
      NIFI_CLUSTER_NODE_PROTOCOL_PORT: "8085"
      NIFI_ZK_CONNECT_STRING: "localhost:2181"
      NIFI_ELECTION_MAX_WAIT: "1 min"
    volumes:
      - ./nifi-vol:/opt/nifi/nifi-current/temp2


  nifi_two:
    image: apache/nifi
    hostname: nifi_two
    container_name: nifi_two
    depends_on:
     - nifi_one
    ports:
      - 8090:8081 # setting a unique port to exemplify this feature 
    environment:
      NIFI_WEB_HTTP_PORT: "8081" # the Nifi listens to port 8081 in the container, which is exposed as 8090 externally
      NIFI_CLUSTER_IS_NODE: "false"
      NIFI_CLUSTER_NODE_PROTOCOL_PORT: "8085"
      NIFI_ZK_CONNECT_STRING: "localhost:2181"
      NIFI_ELECTION_MAX_WAIT: "1 min"
    volumes:
      - ./nifi-vol:/opt/nifi/nifi-current/temp2

volumes:
  nifi: