title: Selenium Grid - How to shutdown the node after execution?
body: <p>I am trying to implement a solution that'd shutdown the node running inside a docker (Swarm) container after a test run.</p>
  
  <p>I looked at docker remove command but cannot use the <strong>docker container rm</strong> command as the containers are at the service-task level</p>
  
  <p>I looked at the /lifecycle-manager api but cannot get to the node from client, the docker stack is running through a nginx server and only one port(4444) gets exposed</p>
  
  <p>Finally I looked at extended the grid node (DefaultRemoteProxy). Excuse my bad java code, this is my first stab at writing java code. With this, it looks like I can stop the node but it gets registered to the hub</p>
  
  <p>How can i stop this re-registration process or start the node without it</p>
  
  <p>My goal is to have a new container for every test and let the docker orchestration bring up a new container when the node is shutdown and container gets removed (docker api <a href="https://docs.docker.com/engine/api/v1.24/" rel="nofollow noreferrer">https://docs.docker.com/engine/api/v1.24/</a>)</p>
  
  <pre><code>public class ExtendedProxy extends DefaultRemoteProxy implements TestSessionListener {
  
      public ExtendedProxy(RegistrationRequest request, GridRegistry registry) {
          super(request, registry);
      }
  
      @Override
      public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
          RequestType type = SeleniumBasedRequest.createFromRequest(request, getRegistry()).extractRequestType();
  
          if(type == STOP_SESSION) {
              System.out.println("Going to Shutdown the Node");
  
             GridRegistry registry = getRegistry();
             registry.stop();
             registry.removeIfPresent(this);
  
          }
      }
  }
  </code></pre>
  
  <p><strong>Hub</strong></p>
  
  <pre><code>[DefaultGridRegistry.assignRequestToProxy] - Shutting down registry.
  [DefaultGridRegistry.removeIfPresent] - Cleaning up stale test sessions on the unregistered node
  [DefaultGridRegistry.add] - Registered a node
  </code></pre>
  
  <p><strong>Node</strong></p>
  
  <pre><code>[ActiveSessions$1.onStop] - Removing session de04928d-7056-4b39-8137-27e9a0413024 (org.openqa.selenium.firefox.GeckoDriverService)
  [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://localhost:4444/grid/register
  [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
  </code></pre>