title: Docker Health Check and Node.js Application
body: <p>I've been trying to include <strong>healthcheck</strong> to my container, however, no matter what i do, container never seems to work. To be precise, i have the following structure:</p>
  
  <ol>
  <li>Traefik Proxy</li>
  <li>Node.js Application behind that proxy</li>
  </ol>
  
  <p>All the labels for <strong>Traefik</strong> are included in the <code>docker-compose.yml</code> file.</p>
  
  <p>Whenever i try to add healthcheck, either in <code>Dockerfile</code> or in <code>docker-compose.yml</code>, application is built and listening for connections on port 443, however, when i try to access address from the browser, it always shows <code>404 error</code> (when <strong>Traefik</strong> is unable to proxy container).</p>
  
  <p>Here is simple <em>service</em> configuration:</p>
  
  <pre><code>frontend:
      restart: always
      build:
        context: ./configuration/frontend
        dockerfile: Dockerfile
      environment:
        - application_environment=development
        - FRONTEND_DOMAIN=HOST_HERE
      volumes:
        - ./volumes/frontend:/app:rw
        - ./volumes/backend/.env:/.env:ro
        - ./volumes/backend/resources/lang:/backend-lang:rw
      labels:
        - traefik.enable=true
        - traefik.frontend.rule=Host:HOST_HERE
        - traefik.port=3000
        - traefik.docker.network=traefik_proxy
        - traefik.frontend.redirect.entryPoint=https
        - traefik.frontend.passHostHeader=true
        - traefik.frontend.headers.SSLRedirect=true
        - traefik.frontend.headers.browserXSSFilter=true
        - traefik.frontend.headers.contentTypeNosniff=true
        - traefik.frontend.headers.customFrameOptionsValue=SAMEORIGIN
        - traefik.frontend.headers.STSPreload=true
        - traefik.frontend.headers.STSSeconds=31536000
      healthcheck:
        test: ["CMD", "cd /app &amp;&amp; yarn healthcheck"]
        interval: 10s
        timeout: 5s
        start_period: 60s
      networks:
        - traefik_proxy
  </code></pre>
  
  <p>And here is <strong>healthcheck.js</strong> file which is accessible through the command <code>yarn healthcheck</code>:</p>
  
  <pre><code>const http = require('https');
  
  const options = {
      host: process.env.FRONTEND_DOMAIN,
      port: 443,
      path: '/',
      method: 'GET',
      timeout: 2000
  };
  
  const healthCheck = http.request(options, (response) =&gt; {
      console.log(`STATUS: ${response.statusCode}`);
      if (response.statusCode === 200) {
          process.exit(0);
      }
      else {
          process.exit(1);
      }
  });
  
  healthCheck.on('error', function (error) {
      console.error('ERROR', error);
      process.exit(1);
  });
  
  healthCheck.end();
  </code></pre>
  
  <p>When I start the container without the <strong>HEALTHCHECK</strong> options (either Dockerfile or compose), it works just fine, page is displayed and when I manually execute <code>yarn healthcheck</code>, then it shows that everything is fine (I mean in the console, <code>STATUS: 200</code>). However, with automated healthcheck, Traefik will have no access to the container.</p>