How can I properly containerize an Express Gatsby application with Docker?

SOLUTION: I am currently working on a project involving an express-gatsby app that needs to be built and deployed using GitHub Actions. To deploy it on Heroku, I have learned that containerizing the app is necessary. As a result, I have created a Dockerfile for this purpose. However, I seem to encounter difficulties during the build process as it gets stuck at npm run install.

If anyone has encountered similar issues or can provide any guidance on resolving this matter, your assistance would be highly appreciated. Thank you in advance.

Here is a screenshot of the docker build process

package.json

 "scripts": {
    "install": "npm install && cd /client && install",
    "build": "cd client/ && npm run build && cd .. && node ./util/build.js",
    "lint": "tslint --project \"tsconfig.json\"",
    "start": "node -r module-alias/register ./dist",
    "start:dev": "nodemon --config nodemon.json",
    "test": "nodemon --config nodemon.test.json"
  },

Dockerfile

FROM node:10-slim

WORKDIR /usr/src/app

RUN npm install -g gatsby-cli

COPY / ./

RUN npm run install

RUN npm run build

EXPOSE 8081

ENV NODE_ENV=production

ENV PORT=8081

RUN ls

CMD ["npm", "run", "start"]

Answer №1

If you're looking to set up npm packages within the client directory, I would recommend adding the following script:

"install": "npm install && cd /client && npm install"

Make sure not to forget including npm in the command.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The module 'AppModule' is importing an unexpected value 'AppAsideModule'. To resolve this issue, make sure to include an @NgModule annotation

Recently, I attempted to upgrade my Angular project from version 13 to version 17. However, during the process, I encountered an error stating "Unexpected value 'AppAsideModule' imported by the module 'AppModule'. Please add an @NgModul ...

Node.js - Error: JSON.Parse and JSON.Stringify are not recognized as functions

Is it possible to convert a string to JSON and vice versa without any additional npm packages? I am currently using JSON.Stringfy in my router.js file. Are there any specific npm modules that need to be added to the project in order to use the JSON.Stringf ...

Are there any alternatives for implementing route support with parameters in express 4.x?

I am currently utilizing expressjs 4.x to construct a basic API that runs on top of mongodb. This API is responsible for serving multiple sets of data: /api/v1/datatype1 /api/v1/datatype2 Each data type requires CRUD operations (post, get, put, delete). ...

Determine the field's type without using generic type arguments

In my code, there is a type called Component with a generic parameter named Props, which must adhere to the Record<string, any> structure. I am looking to create a type that can accept a component in one property and also include a function that retu ...

The function for batch insertion only functions with Postgresql and SQL Server databases

I am a beginner in JavaScript and I am currently working on creating a new restaurant. I have come across a code snippet that inserts a relation into a join-table: await newRestaurant.$relatedQuery('tags', trx).relate(tagIds); Is it not possible ...

The yauzl callback parameter is experiencing an issue where it is undefined on one computer, but functions correctly on

Currently attempting to execute: yauzl.open(path, options, (err, zipfile) => { //code }) Expecting the variable zipfile to be of type ZipFile Strange issue where it works on one computer but returns undefined on the other. The only variance betwe ...

Error encountered while fetching client credentials in Next-Auth Credential-Provider [next-auth]

Exploring the combination of nextjs and next-auth for authentication using a credential provider has been intriguing. However, I've encountered an issue when attempting to access a protected route while logged in: [next-auth][error][client_fetch_error ...

Exploring Immediately Invoked Function Expressions in TypeScript

I came across an interesting article on self-invoking functions in JavaScript by Minko Gechev. This article teaches us how to create a JavaScript function that calls itself immediately after being initialized. I am curious about how we can achieve this in ...

Is it possible to share a file download using just Node.js without the need for express?

app.get('/retrieve', function(req, res){ const fileToRetrieve = `${__dirname}/documents-folder/dramaticpenguin.MOV`; res.download(fileToRetrieve); // Download the specified file. }); ...

"Pairing AngularJS 2 with Vaadin for a winning combination

Good day, I'm currently following a tutorial but encountering some challenges with integrating Vaadin and Angularjs2 into my Joomla Backend project. The error message I am facing is as follows: polymer-micro.html:196 Uncaught TypeError: Cannot read ...

"You may not be able to access the property of undefined, however, you can still output it

Recently, I've been encountering an issue with retrieving and passing data in an Express post request. The problem arises when trying to access a property of incoming data resulting in a TypeError: "Cannot read property 'text' of undefined." ...

I am unable to integrate Autoprefixer into an Express project

I am having trouble adding Autoprefixers to the postcssmiddleware, as mentioned in the documentation here I also attempted using express-autoprefixers but still cannot see the vendors in my dest or public folder. You can find a link to my repository (node ...

Vue 3 Electron subcomponents and routes not displayed

Working on a project in Vue3 (v3.2.25) and Electron (v16.0.7), I have integrated vue-router4 to handle navigation within the application. During development, everything works perfectly as expected. However, when the application is built for production, the ...

Please ensure that all files have finished downloading before proceeding to create the object

Within my Session class, I've been instantiating objects from my Question Class. Within this process, images are being downloaded to a local path. However, the issue arises when my LaTeXDoc class demands that all images are already saved at the time o ...

Typescript: Determining the return type of a function based on its input parameters

I've been working on a function that takes another function as a parameter. My goal is to return a generic interface based on the return type of the function passed in as a parameter. function doSomething <T>(values: Whatever[], getter: (whatev ...

Exploring the integration of Styled-components in NextJs13 for server-side rendering

ERROR MESSAGE: The server encountered an error. The specific error message is: TypeError: createContext only works in Client Components. To resolve this issue, add the "use client" directive at the top of the file. More information can be found here i ...

What is the best way to cause an error to occur upon launching an ExpressJS server?

Below is a brief code snippet I've provided: ... const url = typeof process.env.url === 'string' ? process.env.url : {do not start a server} ... server.start(options, ({ port }) => console.log(`Server is running on http://localhost:${po ...

Having trouble with Passport.js, Express, and Google OAuth resulting in a 502 Bad Gateway error

I have been working on implementing a basic Google OAuth for my Express.js application using passport.js by following this tutorial (simply replacing facebook with google) https://github.com/passport/express-4.x-facebook-example/blob/master/server.js Ever ...

Using TypeScript: Retrieve enum type value in type definition

I'm encountering an issue while attempting to define a specific type based on the value of an enum. enum E { A = "apple", B = "banana", C = "cherries" } // Defining the type EnumKey as 'A' | 'B ...

Best practices for building full-stack applications using Node.js and AWS

After focusing on front-end development, I am venturing into creating my first full-stack application integrating node.js, express, and AWS. As I delve into the design stage, I have encountered a few challenges and seek your expertise with the following ...