How can I make my express server app work in a docker container?

I have the following express server app which (locally) serves as my GraphQL server:

import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import * as Schema from './schema';

const cors = require('cors');

const PORT = 3001;
const server = express();

const schemaFunction =
  Schema.schemaFunction ||
  function() {
    return Schema.schema;
  };
let schema;
const rootFunction =
  Schema.rootFunction ||
  function() {
    return schema.rootValue;
  };
const contextFunction =
  Schema.context ||
  function(headers, secrets) {
    return Object.assign(
      {
        headers: headers,
      },
      secrets
    );
  };

server.use(cors());
server.use('/graphql', bodyParser.json({limit: '50mb'}), graphqlExpress(async (request) => {
  if (!schema) {
    schema = schemaFunction(process.env)
  }
  const context = await contextFunction(request.headers, process.env);
  const rootValue = await rootFunction(request.headers, process.env);

  return {
    schema: await schema,
    rootValue,
    context,
    tracing: true,
  };
}));

server.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql',
  query: `# Run some stuff
`,
}));

server.listen(PORT, () => {
  console.log(`GraphQL Server is now running on http://localhost:${PORT}/graphql`);
  console.log(`View GraphiQL at http://localhost:${PORT}/graphiql`);
});

I’ve recently tried putting this onto my Linux server using Docker, however I can’t access the endpoint internally or externally.

My Dockerfile looks like this:

FROM node
RUN mkdir /server
WORKDIR /server
COPY package.json /server
RUN npm install
COPY . /server
CMD ["npm", "run", "server"]

And I run it with this: docker run -p 3001:3001 9ab9781fb318

I can’t access it (i.e. call the endpoint) externally, even though port 3001 is allowed in my firewall settings, or internally.

Source: StackOverflow