我对这个Docker世界很陌生,我正试图从aws ECR部署一个图像(nodejs-typescript服务)到aws ECS,但当我在集群内创建服务时,出现了这个错误,taks从未运行:
exec /usr/local/bin/docker-entrypoint.sh: exec format error
我的Dockerfile是这样的:
FROM node:lts-alpine
WORKDIR /usr/app
COPY package*.json ./
COPY tsconfig*.json ./
RUN yarn install --quiet
RUN yarn global add pm2
COPY . .
RUN yarn build
CMD ["pm2-runtime", "build/src/localServer.js"]
当我构建图像并运行它时,它在我的pc上工作正常:
(base) MacBook-Pro api % docker run -it -p 3000:3000 api-dev
2022-12-06T15:35:27: PM2 log: Launching in no daemon mode
2022-12-06T15:35:27: PM2 log: App [localServer:0] starting in -fork mode-
2022-12-06T15:35:27: PM2 log: App [localServer:0] online
Connected to my_mongo_db_cluster
🚀 Server ready at: http://localhost:3000/
任务定义在Linux/X86_64上运行
对于找出问题所在有什么建议或提示吗?谢谢!
编辑:当我添加一个ENTRYPOINT到我的Dockerfile像这样
# same steps
COPY . .
RUN yarn build
ENTRYPOINT ["pm2-runtime", "build/src/localServer.js"]
它抛出这个错误exec /usr/local/bin/pm2-runtime: exec format error
。当我将pm2-runtime
更改为node
# same steps
COPY . .
RUN yarn build
ENTRYPOINT ["node", "build/src/localServer.js"]
希望有帮助。
我找到了问题所在。这是我的苹果M1芯片在施展它的不兼容魔法。对于那些有同样问题的人,只需在Dockerfile中添加平台--platform=linux/amd64
似乎就可以解决问题:
FROM --platform=linux/amd64 node:lts-alpine
# more instructions...