Solution Required for nginx: [emerg] bind() to failed (13: Permission denied)


I am currently exploring the usage of the Nginx Docker image within our project. I have to run the container as non-root user binding to the ports 80/443 in secure way. Am facing permission denied issue due to non-root user. How to bind to port 80/443 as non-root user?


FROM alpine:3.15.4 (base image)
add nginx, openjdk11-jre-headless and bash

//add non-root user
RUN addgroup -g 3080 -S xyz && adduser -u 3080 -S -G xyz xyz
USER xyz

//copy nginx config files
//copy backend java jar files
CMD ["/bin/bash", "/opt/"] - starts java and nginx process.


# Start the first process
java -jar /opt/backend/springdocker-0.0.1-image.jar &

# Start the second process
nginx -g "daemon off;" &

wait -n
exit $?

Error: nginx: [emerg] bind() to failed (13: Permission denied)
Please provide solutions to fix this issue.

Thank you.

Linux does not allow to bind a port below 1024 with an unprivileged user. It is not a restriction introduced by docker or containers in general. That’s why people usually use 8080/8443 instead and map host port 80 to 8080 and host port 443 to 8443.

1 Like