我的目标是在 Heroku 中运行一个 docker 容器。我可以在本地构建中运行该容器。当我使用 Github 操作进行部署时,日志显示由于权限被拒绝错误,dockerfile 中的启动 CMD 未运行。
我使用了 Github 操作,因为heroku container:push web
给了我405 Method Not Allowed
,然后我尝试了这个,它发挥了它的作用。
作为参考,一些文件如下:
Dockerfile:
# FINAL STAGE
FROM alpine
# Install packages
RUN apk update
RUN apk add nginx nginx-mod-http-brotli nodejs npm supervisor
# Server
WORKDIR /app/server
COPY server/package.json server/package-lock.json ./
RUN npm ci
COPY server/src src
# Client
WORKDIR /app/client
COPY --from=build client/dist dist
# supervisord and nginx
WORKDIR /app
COPY supervisord.conf .
COPY nginx.conf.template .
# Runtime scripts
WORKDIR /app
COPY scripts/fillNginxConf.js scripts/
COPY runtime.sh .
# Start
RUN chown -R nginx:nginx /app
RUN chown -R nginx:nginx /etc/nginx/
USER nginx
WORKDIR /app
CMD ["/app/runtime.sh"]
运行时
#!/bin/sh
cd /app/scripts
node fillNginxConf.js
cd ..
supervisord -c supervisord.conf
操作完成但应用程序崩溃并且 Heroku 日志如下:
2024-11-22T12:48:56.893890+00:00 app[api]: Release v78 created by user berkan
2024-11-22T12:48:56.893890+00:00 app[api]: Deployed web (5b109766c096) by user berkan
2024-11-22T12:48:58.295090+00:00 heroku[web.1]: State changed from crashed to starting
2024-11-22T12:49:03.404885+00:00 heroku[web.1]: Starting process with command `/app/runtime.sh`
2024-11-22T12:49:04.146069+00:00 app[web.1]: /bin/sh: /app/runtime.sh: Permission denied
2024-11-22T12:49:04.204831+00:00 heroku[web.1]: Process exited with status 126
2024-11-22T12:49:04.235181+00:00 heroku[web.1]: State changed from starting to crashed
我将非常感激得到一些帮助,我迷路了。
试试这个,
当您复制脚本时,它不会自动获得
+x
可执行权限。希望这有帮助