无法在 M1 Macbook 上启动 Cloud 运行 容器
Unable to start a Cloud Run container on M1 Macbook
我没有在我的 M1 Macbook 上安装 Rosetta。已安装 Docker 和所有 deps,这甚至工作了几次,但不确定是什么原因突然导致此错误:
Starting to run the app using configuration 'Cloud Run: Run/Debug Locally' from .vscode/launch.json...
To view more detailed logs, go to Output channel : "Cloud Run: Run/Debug Locally - Detailed"
Dependency check started
Dependency check succeeded
Starting minikube, this may take a while.............
minikube successfully started
The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration /Users/myname/Code/myprojectAPI/.vscode/launch.json
Configuring minikube gcp-auth addon
Using GCP project 'myproject-com' with minikube gcp-auth
Update initiated
Build started for artifact myprojectapi
Build completed for artifact myprojectapi
Deploy started
Deploy completed
Status check started
Resource pod/myprojectapi-8695998b94-9lk7d status updated to In Progress
Resource pod/myprojectapi-8695998b94-9lk7d status updated to In Progress
Resource deployment/myprojectapi status failed with waiting for rollout to finish: 0 of 1 updated replicas are available...
Status check failed
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
1/1 deployment(s) failed
Skaffold exited with code 1.
Cleaning up...
Finished clean up.
Dockerfile
:
FROM gcr.io/google.com/cloudsdktool/cloud-sdk:slim
RUN set -ex; \
apt-get -y update; \
curl -fsSL https://deb.nodesource.com/setup_17.x | bash -; \
apt-get -y install nodejs; \
apt-get -y install ghostscript; \
apt-get -y install pngquant; \
rm -rf /var/lib/apt/lists/*
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install dependencies.
# If you add a package-lock.json speed your build by switching to 'npm ci'.
RUN npm ci --only=production
# RUN npm install --production
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
CMD [ "npm", "start" ]
我正在使用 Cloud Code 扩展 'Cloud Run Emulator' 在 VS Code 中进行部署。
我做错了什么?
我可以确认您 Dockerfile
中使用的 gcr.io/google.com/cloudsdktool/cloud-sdk:slim
图像是 x86_64 图像,它与基于 ARM64 的 M1 Mac 不兼容。由于 CloudSDK 目前没有任何基于 ARM64 的镜像,因此有必要使用 CloudSDK 创建您自己的基础镜像。这样做的步骤是:
- 将
Dockerfile
中指向 gcr.io/google.com/cloudsdktool/cloud-sdk:slim
的行更新为新的基本图像(例如 debian:buster-slim
)
- 将 CloudSDK 工具安装到图像上。它在您的
Dockerfile
: 中应该看起来像这样
# Downloads the gCloud package
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
# Installs the package
RUN mkdir -p /usr/local/gcloud \
&& tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz \
&& /usr/local/gcloud/google-cloud-sdk/install.sh --quiet
# Adds the package path to local
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
完成这些步骤后 运行,您应该会得到一个安装了 CloudSDK 的新基础映像!如果您对某些上下文或其他配置选项感到好奇,请查看 Docker documentation page about multi-arch support
我没有在我的 M1 Macbook 上安装 Rosetta。已安装 Docker 和所有 deps,这甚至工作了几次,但不确定是什么原因突然导致此错误:
Starting to run the app using configuration 'Cloud Run: Run/Debug Locally' from .vscode/launch.json...
To view more detailed logs, go to Output channel : "Cloud Run: Run/Debug Locally - Detailed"
Dependency check started
Dependency check succeeded
Starting minikube, this may take a while.............
minikube successfully started
The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration /Users/myname/Code/myprojectAPI/.vscode/launch.json
Configuring minikube gcp-auth addon
Using GCP project 'myproject-com' with minikube gcp-auth
Update initiated
Build started for artifact myprojectapi
Build completed for artifact myprojectapi
Deploy started
Deploy completed
Status check started
Resource pod/myprojectapi-8695998b94-9lk7d status updated to In Progress
Resource pod/myprojectapi-8695998b94-9lk7d status updated to In Progress
Resource deployment/myprojectapi status failed with waiting for rollout to finish: 0 of 1 updated replicas are available...
Status check failed
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
1/1 deployment(s) failed
Skaffold exited with code 1.
Cleaning up...
Finished clean up.
Dockerfile
:
FROM gcr.io/google.com/cloudsdktool/cloud-sdk:slim
RUN set -ex; \
apt-get -y update; \
curl -fsSL https://deb.nodesource.com/setup_17.x | bash -; \
apt-get -y install nodejs; \
apt-get -y install ghostscript; \
apt-get -y install pngquant; \
rm -rf /var/lib/apt/lists/*
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install dependencies.
# If you add a package-lock.json speed your build by switching to 'npm ci'.
RUN npm ci --only=production
# RUN npm install --production
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
CMD [ "npm", "start" ]
我正在使用 Cloud Code 扩展 'Cloud Run Emulator' 在 VS Code 中进行部署。
我做错了什么?
我可以确认您 Dockerfile
中使用的 gcr.io/google.com/cloudsdktool/cloud-sdk:slim
图像是 x86_64 图像,它与基于 ARM64 的 M1 Mac 不兼容。由于 CloudSDK 目前没有任何基于 ARM64 的镜像,因此有必要使用 CloudSDK 创建您自己的基础镜像。这样做的步骤是:
- 将
Dockerfile
中指向gcr.io/google.com/cloudsdktool/cloud-sdk:slim
的行更新为新的基本图像(例如debian:buster-slim
) - 将 CloudSDK 工具安装到图像上。它在您的
Dockerfile
: 中应该看起来像这样
# Downloads the gCloud package
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
# Installs the package
RUN mkdir -p /usr/local/gcloud \
&& tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz \
&& /usr/local/gcloud/google-cloud-sdk/install.sh --quiet
# Adds the package path to local
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
完成这些步骤后 运行,您应该会得到一个安装了 CloudSDK 的新基础映像!如果您对某些上下文或其他配置选项感到好奇,请查看 Docker documentation page about multi-arch support