Next.js镜像部署AKS遇exec格式错误,架构匹配仍未解决
问题:Next.js容器部署AKS出现CrashLoopBackOff,报错exec format error
我为Next.js应用制作了自定义Docker镜像并推送到Azure容器注册表(ACR),部署到Azure Kubernetes服务(AKS)集群的Pod后,Pod状态显示为CrashLoopBackOff,Pod日志报错:
exec /usr/local/bin/docker-entrypoint.sh: exec format error
此前曾因构建镜像的架构与AKS节点(Linux/AMD64)不匹配(本地为ARM架构)出现该问题,但切换到amd64架构构建后,错误依旧。已确认当前镜像和节点架构均为amd64:
- 使用命令
docker buildx build --platform linux/amd64 -t <container_url>/<container_image>:<tag> . --load构建amd64镜像 - 用
docker push <container_url>/<container_image>:<tag>推送到ACR - 本地运行
docker run --platform linux/amd64 -it --rm <acr_name>.azurecr.io/<image_name>:v0.1.0验证镜像正常启动 - 通过
docker image inspect <image_id>确认镜像架构为amd64,kubectl get nodes -o=jsonpath='{.items[0].status.nodeInfo.architecture}'确认节点架构为amd64
我还尝试在Dockerfile开头添加shebang,且设置了ENTRYPOINT [],但镜像历史仍显示/bin/sh -c #(nop) ENTRYPOINT ["docker-entrypoint.sh"]。
配置文件内容
Dockerfile
#!/bin/bash # Use an official Node.js runtime as the parent image FROM node:16 # Update and install dependencies RUN apt-get update && apt-get install -y curl gnupg # Install Yarn RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt-get update && apt-get install -y yarn # Clean up RUN apt-get clean && rm -rf /var/lib/apt/lists/* # Set the working directory inside the container WORKDIR /usr/src/app # Copy .npmrc or .yarnrc for private package access COPY .npmrc .npmrc # Copy package.json and package-lock.json (or yarn.lock) to the container COPY package*.json ./ # Copy the application code to the container COPY . . # Install the application's dependencies inside the container RUN yarn install # Remove .npmrc or .yarnrc after installation RUN rm -f .npmrc # Build the Next.js app RUN yarn build # Override the default entrypoint ENTRYPOINT [] EXPOSE 3000 # Specify the command to run when the container starts CMD [ "yarn", "start" ]
deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: <placeholder> spec: selector: matchLabels: app: <placeholder> replicas: 1 template: metadata: labels: app: <placeholder> spec: containers: - name: <container_name> image: <container_url>.azurecr.io/<repo_name>:<version_#> ports: - containerPort: 3000 imagePullSecrets: - name: <secret>
service.yaml
apiVersion: v1 kind: Service metadata: name: <app_name> spec: selector: app: <app_name> ports: - protocol: TCP port: 3000 targetPort: 3000 # Match this to the containerPort above. type: LoadBalancer
我的Next.js应用是通过npx create-next-app@latest生成的,未做代码修改。
请问如何解决该错误?或有哪些进一步诊断的方法?另外,若有近年关于将Next.js容器化并部署到AKS的深度教程也请推荐,谢谢!
内容的提问来源于stack exchange,提问作者deepfriedchicken
相关产品推荐
相关产品推荐

