Reputation: 6506
I have set a Nginx to listen on a port 8080
in files/etc/nginx/conf.d/default.conf
by adding listen 8080;
to the only one server block I have.
I run Nginx by docker run with -p 8080:8080
I would like to ask why there is 80/tcp
under PORTS of docker ps
command as below?
STATUS NAMES IMAGE PORTS
Up 6 minutes docker-nginx docker-nginx:1.17.8 80/tcp, 0.0.0.0:8080->8080/tcp
command docker inspect docker-nginx
shows:
"HostConfig": {
"PortBindings": {
"8080/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
"Config": {
"ExposedPorts": {
"80/tcp": {},
"8080/tcp": {}
},
"NetworkSettings": {
(...)
"Ports": {
"80/tcp": null,
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
]
},
My intention is to have Nginx listen only to 8080
and not be accessible under any other port even by other containers belonging to the same network as Nginx. How to make Nginx not exposing the 80/tcp
port?
I'm using a build that is FROM an official nginx:1.17.8
image.
Upvotes: 3
Views: 2806
Reputation: 1951
The Dockerfile for the Nginx image should have the expose
instruction for port 80. On the Nginx website, you should be able to find the dockerfile for the image you are using, and should have the expose 80
command.
If you do not want the port 80 exposed, even though it will not be used if you are using port 8080, then remove or comment out expose 80
in the Dockerfile and then build the image.
Upvotes: 2