title: Cannot Connect to Dockerized Express HTTPS Server
body: <p>I'm trying to serve my app over HTTPS so that I can use a service worker with my React app. </p>
  
  <p>To do this, I added https.createServer() to my Express startup script </p>
  
  <pre><code>#!/usr/bin/env node
  
  /**
   * Module dependencies.
   */
  
  var app = require('../app');
  var debug = require('debug')('robotapp:server');
  var http = require('http');
  var fs = require('fs');
  var https = require('https');
  
  /**
   * Get port from environment and store in Express.
   */
  
  var port = normalizePort(process.env.PORT || '8000');
  app.set('port', port);
  console.log('Listening on localhost:', port);
  
  /**
   * Create HTTP server.
   */
  
  var server = http.createServer(app);
  
  /**
   * Add HTTPS server
   */
  
  if (process.env.NODE_ENV === 'prod') {
      https
          .createServer(
              {
                  key: fs.readFileSync('sslcerts/server.key', 'utf8'),
                  cert: fs.readFileSync('sslcerts/server.pem', 'utf8')
              },
              app
          )
          .listen(443, function() {
              console.log('HTTPS listening on PORT 443');
          });
  }
  
  /**
   * Listen on provided port, on all network interfaces.
   */
  
  server.listen(port);
  server.on('error', onError);
  server.on('listening', onListening);
  
  /**
   * Normalize a port into a number, string, or false.
   */
  
  function normalizePort(val) {
      var port = parseInt(val, 10);
  
      if (isNaN(port)) {
          // named pipe
          return val;
      }
  
      if (port &gt;= 0) {
          // port number
          return port;
      }
  
      return false;
  }
  
  /**
   * Event listener for HTTP server "error" event.
   */
  
  function onError(error) {
      if (error.syscall !== 'listen') {
          throw error;
      }
  
      var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
  
      // handle specific listen errors with friendly messages
      switch (error.code) {
          case 'EACCES':
              console.error(bind + ' requires elevated privileges');
              process.exit(1);
              break;
          case 'EADDRINUSE':
              console.error(bind + ' is already in use');
              process.exit(1);
              break;
          default:
              throw error;
      }
  }
  
  /**
   * Event listener for HTTP server "listening" event.
   */
  
  function onListening() {
      var addr = server.address();
      var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
      debug('Listening on ' + bind);
  }
  </code></pre>
  
  <p>When I build the Docker container and start the app, both the HTTP and HTTPS server start up (I can see the "Listening on localhost:8000" and "HTTPS listening on PORT 443" messages). I can successfully access the HTTP version of my app on PORT 8000, but when I go to access PORT 443 on my server I get a "This site cannot be reached" error.</p>
  
  <p>At first I thought maybe I mapped my container ports wrong, but I checked and nothing seems out of ordinary</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                          NAMES
  16d0013eec8a        robotapp:2.1        "npm start"         4 seconds ago       Up 3 seconds        0.0.0.0:443-&gt;443/tcp, 0.0.0.0:8000-&gt;8000/tcp   silly_tesla
  </code></pre>
  
  <p>If anyone has any suggestions as to what I'm doing wrong, please let me know :)</p>