how to cancel the docker container expose port - docker

I docker pull a official image from dockerHUB.
when the docker container run up,
use docker ps -a to check, found the PORTS column show some ports, such as:
CONTAINER ID IMAGE PORTS NAMES
07d3eea2018c consul 8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp xxxx
I just want 8500 port, so how to remove or cancel other ports? THANKS!

Related

unable to connect to docker redis on windows from outside the docker instance

I've followed answers on other questions here on SO and via google but still unable to connect. Below is my attempt. I appreciate any suggestions to get this working.
Note all the firewalls are disabled during this test.
PS C:\WINDOWS\system32> docker run -d --name myredis -p 6379:6379 redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
f5d23c7fed46: Pull complete
a4a5c04dafc1: Pull complete
605bafc84bc9: Pull complete
f07a4e35cd96: Pull complete
17944e5e3eb7: Pull complete
6f875a8605e0: Pull complete
Digest: sha256:8888f6cd2509062a377e903e17777b4a6d59c92769f6807f034fa345da9eebcf
Status: Downloaded newer image for redis:latest
3f65a413985e513ef3e9a578b09a3c8729a214c767197d9e34268a38114e39c6
PS C:\WINDOWS\system32> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f65a413985e redis "docker-entrypoint.s…" 7 seconds ago Up 6 seconds 0.0.0.0:6379->6379/tcp myredis
PS C:\WINDOWS\system32> docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myredis
172.17.0.2
PS C:\WINDOWS\system32> docker exec -it myredis redis-cli
127.0.0.1:6379> ping
PONG
The above indicates (to me) that redis is running on the docker image and listening on port 6379 on both the docker image and host machine. From another powershell, I run redis client for windows and it just hangs
PS D:\Program Files\Redis> ./redis-cli
127.0.0.1:6379> connect 172.17.0.2 6379
The docker run -p option publishes the service's port on the host's IP address, and from outside of Docker you can connect to that. If you are specifically on the console of the same physical host running the container, you can use the special host name localhost or the matching special IPv4 address 127.0.0.1 to reach the container. (If you're inside a container, though, localhost usually means "this container".)
In your final redis-cli command where it says it's connected to 127.0.0.1:6379, you've already connected to the containerized Redis: you're done.
You never need the IP address returned by docker inspect, and it's unreachable in several very common setups; I would recommend never trying to look it up at all. If you're on a different host, or you're using Docker for Mac or Docker Toolbox, you will be unable to reach the Docker-private IP addresses, for example. The way you've done it with docker run -p is correct.

I cannot access proxy of a running docker container

I have a running Docker container which shows PORTS 9191/tcp. So on my browser, I tried accessing server using localhost:9191/api/.... However, browser throws an error This site can’t be reached
Here is a log to docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c214aefed15e shah "youtube-dl-server -…" 6 seconds ago Up 5 seconds 9191/tcp boring_swirles
This is what my docker file looks like
FROM mariozig/youtube-dl_server
RUN pip install --pre youtube_dl_server
EXPOSE 9191
ENTRYPOINT ["youtube-dl-server", "--host=0.0.0.0"]
You have not mapped the docker container port to host port.
The docker container runs on a host. And The host doesn't know which requests to be directed to the docker container. For that you have to to map the host port to docker container port using -p flag in docker run command as shown below:
docker run -d -p HOST_PORT:CONTAINER_PORT IMAGE_NAME
-p in this command will specify that you are forwarding your host port to the container port. In your local host in the port HOST_PORT will call the port CONTAINER_PORT of your container.
Now when you will access the HOST_IP:HOST_PORT then the host will redirect the request to corresponding container with which this HOST_PORT has been mapped.
For example I started a tomcat docker container and mapped the tomcat container's 8080 port to host's 9092 port by using the above command. When I do docker ps I can see the mapping under PORTS as 0.0.0.0:9092->8080/tcp

Edit docker container settings while container is running

I have a docker container which is running with port mapping.
cce2ca6eb83b nginx "nginx -g 'daemon off" 5 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp www-nginx
Now I want to change host port from 80 to 8080. How can I do that?
docker update
does not have any option to change the network settings.
You can't edit the port mapping for running container. docker update command is used to prevent containers from consuming too many resources from their Docker host and also to dynamically set restart policy but not port mapping.
A work around for what you want to achieve could be to create a new image from your current container and then start a new container from the newly created image with the port 8080 as follow:
docker stop www-nginx
docker commit www-nginx www-nginx-2
docker run -p 8080:80 -td www-nginx-2
You can't edit the port mapping on a container, you will have to create a new container.

Docker port not overriden

I want to expose a docker container port on a different host port.
docker run -d --net="host" --name="couchpotato2" -p 5555:5050 ...
However, I don't get the mapping of 5555 -> 5050. Any idea why?
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
114ae1617632 needo/couchpotato "/sbin/my_init" 3 seconds ago Up 2 seconds couchpotato3
Here is the docker image I'm using:
https://github.com/needo37/couchpotato
Your problem is the use of host networking:
--net="host"
Explained in the documentation
Publishing ports and linking to other containers will not work when
--net is anything other than the default (bridge).

Run docker with all ports open

I want to start docker but the VNC ports keep changing everytime i start docker container. So I was wondering if there is anyway to start docker image with ALL Ports OPEN?
-p external port:internal port (e.g. -p 80:80) if you wanted it to map port 80 in the container to port 80 on the host O/S. Docker documentation.

Resources