How to deploy a MERN app on Google Cloud with a custom domain and Which is best way to deploy App Engine or cloud run I have already created account GCP
Hello @Vikramjeet11
MERN stack deployment involves deploying a MongoDB, Express.js, React, and Node.js application to a cloud platform. This typically involves setting up a server, configuring databases, and managing the application's lifecycle.
Deploying a MERN (MongoDB, Express, React, Node.js) app on Google Cloud Platform (GCP) with a custom domain involves several steps. Below is a systematic guide to help you through the process, including considerations for using App Engine or Cloud Run.
# Use Node.js base image FROM node:14 # Set working directory WORKDIR /app # Copy package.json and install dependencies COPY package*.json ./ RUN npm install # Copy the rest of the application code COPY . . # Build the React app RUN npm run build # Start the server CMD ["npm", "start"]
docker build -t gcr.io/[PROJECT-ID]/mern-app .
docker push gcr.io/[PROJECT-ID]/mern-app
gcloud run deploy mern-app --image gcr.io/[PROJECT-ID]/mern-app --platform managed --region [REGION]
runtime: nodejs14 env: standard
gcloud app deploy
what is the process for creating virtual instance and if don't have github repo is there any other option to push code and I have separate folder for react and node in same project so I have to create a individual yml file for that or not neccesssary
What a great writeup, learn2skills!
One thing I'd add: As a product manager on the Serverless team which ships both Cloud Run and App Engine, I'd recommend going with Cloud Run rather than App Engine unless you have a strong reason to choose App Engine. Cloud Run is a much newer product with better portability and interoperability, so it's a better choice for a new application. And you can delpoy from source:
gcloud run deploy SERVICE --source .
Cloud Run works with Cloud Build in the background to build your image, so you never have to touch a container if you don't want to.