Aragon
Aragon

Reputation: 143

Restrict a port running on docker in ubuntu

I have a server running inside a docker container. Server is running on port 8080. I would like to not expose this port to outside but only wanted to accessible from inside. Currently it can be accessed from outside. I have tried the following command, but it didn't help me.

sudo ufw deny 8080

Can someone help me?

Upvotes: 0

Views: 224

Answers (1)

Ratish Bansal
Ratish Bansal

Reputation: 2462

There are two different mechanisms that directly involve network ports: exposing and publishing ports.

  • You expose ports using the EXPOSE keyword in the Dockerfile or the --expose flag to docker run. Exposing ports is a way of documenting which ports are used, but does not actually map or open any ports.

  • You publish posts using the --publish or --publish-all or -p flag to docker run. This tells Docker which ports to open on the container’s network interface.

So, please check your command you are running to start the container. Since you don't want to access the container from outside, you should not use -p. You can refer to the link below for more details.

https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose

Upvotes: 1

Related Questions