Deploy NestJS in Google Cloud Run

Viewed 51

I have nestjs app running on GCP-VM and it runs well. But, I need to use Cloud Run for my backend services. I tried to run it on Cloud Run Emulator at my VSCode first, but resulting error:

The image was built but failed to start on the cluster. Because you are on an ARM64 machine, it is likely that you built an ARM64 image for an x86_64 cluster. Update failed with error code STATUSCHECK_CONTAINER_TERMINATED

But I think this is not the real problem because when I run it on my local docker (MacOS Apple M1), it works.

While it can run at my local docker: enter image description here

This is my Dockerfile:

FROM node:18-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . ./
CMD ["npm", "start"]

And here is my docker-compose.yml:

version: '1.0'

services:
  #mongodb services
  mongo_db:
    container_name: db_container
    image: mongo:latest
    restart: always
    ports:
      - 2717:27017
    volumes:
      - mongo_db:/data/db

  #node API service
  api:
    build: .
    # ports:
    #   - 4000:3000
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    environment:
      PORT: 3000
      MONGO_URI: mongodb://mongo_db:27017
      DB_NAME: mp-svc
      NAME: MP-SVC
    depends_on:
      - mongo_db

  nginx:
    image: nginx:latest
    volumes:
      - ./conf.d:/etc/nginx/conf.d
    depends_on:
      - api
    ports:
      - 3000:3000

volumes:
  mongo_db: {}

How can I deploy my dockerize nestjs app in Cloud Run? I’m using MacOS with Apple M1.

1 Answers

Your container was built for ARM64. You need to build the container for X64.

DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build

Note: delete the node:18-alpine image first, so that the correct platform version is downloaded.

docker image rm node:18-alpine
docker image rm mongo:latest
Related