Docker Alpine Node JS Image Bind to Port 80

Spread the love

I didn’t face the issue with Docker desktop, but with Kubernetes pod. When checked the logs of container the error was Eaccess, not permission, cannot bind to port 80. It was an issue because ports below 1024 are privileged.

I didn’t face this issue in docker desktop, may be because docker desktop removes the privileged port restriction (Reference)

So had to add few more lines to docker to fix it:

# switch user
USER root

RUN apk update
# install set capability lib
RUN apk add libcap-setcap
# update capability
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node
# switch to non root user
USER nextjs

And it will fix you issue

Cheers and Peace out!!!

Leave a Reply

Your email address will not be published. Required fields are marked *