Running httpd in container as non-root user using port 80

+2 votes
I have been trying to set uid in centos container as a non root user to run on port 80, is there a Dockerfile or compose that actually sets user to apache and runs on port 80
Aug 9, 2019 in Docker by Ray

recategorized Aug 9, 2019 by Kalgi 5,831 views

2 answers to this question.

+1 vote

You could probably try adding this cmd in your dockerfile:

RUN setcap CAP_NET_BIND_SERVICE=+eip /path/to/binary

use setcap on the binary itself rather than a symlink.

answered Aug 9, 2019 by Sirajul
• 59,230 points
0 votes

Any port under 1024 cannot be opened or used by a non-root user. One of the workaround as using CAP_NET_BIND_SERVICE as mentioned by @Sirajul. 

The other way is redirecting connection from port 80 to port 8080 as that port is accessible by non-root users. Now instead of using accessing apache on port 80, you can access it on port 8080. 

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

You'll have to redirect it with a root user.

answered Aug 9, 2019 by Kalgi
• 52,350 points

Related Questions In Docker

+1 vote
1 answer
0 votes
1 answer

Is it possible to start a shell session in a running container (without ssh)

use this docker exec -it "id of running ...READ MORE

answered Jul 25, 2018 in Docker by Kalgi
• 52,350 points
879 views
0 votes
1 answer

Is it possible to start a shell session in a running container (without ssh)

use this docker exec -it "id of running ...READ MORE

answered Jul 27, 2018 in Docker by Kalgi
• 52,350 points
743 views
0 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,687 views
0 votes
1 answer

Why do I get Connection reset by peer when making a request to a service running in a container?

Typically, this message is returned if the ...READ MORE

answered Jul 10, 2019 in Docker by Sirajul
• 59,230 points
4,291 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP