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 8 in Docker by Ray

recategorized Aug 9 by Kalgi 157 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 by Sirajul
• 31,180 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 by Kalgi
• 41,760 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
• 41,760 points
50 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
• 41,760 points
47 views
0 votes
1 answer
0 votes
1 answer
0 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
• 56,900 points
189 views
0 votes
1 answer