My goal is to run a docker container in Heroku. I can run the container in a local build. When I deploy with Github actions, logs say that the startup CMD in the dockerfile wasn't run due to a permission denied error.
I used Github actions because heroku container:push web
gave me 405 Method Not Allowed
, then I tried this, which did its part.
For reference, some files are as below:
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"]
runtime.sh
#!/bin/sh
cd /app/scripts
node fillNginxConf.js
cd ..
supervisord -c supervisord.conf
The action completes but the app crashes and the Heroku logs are:
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
Some help would be appreciated, I am lost.
Try this,
# Runtime scripts
WORKDIR /app
COPY scripts/fillNginxConf.js scripts/
COPY runtime.sh .
#ADD THIS LINE
RUN chmod +x ./runtime.sh
# Start
RUN chown -R nginx:nginx /app
RUN chown -R nginx:nginx /etc/nginx/
USER nginx
WORKDIR /app
CMD ["/app/runtime.sh"]
When you copy a script over it doesn't automatically get the +x
executable permission.
Note: This permission will apply to users:groups:others.
You can check out the chmod
manual here on different ways to use this command.
For now you, if you want to limit only to your current user you can use
chmod u+x ./runtime.sh
Hope this helps