Edit docker container settings while container is running - docker

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.

Related

how to cancel the docker container expose port

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!

Redirect same port of two Docker containers on different ports

I need to run a Java app into several Docker containers in order to isolate their execution.
This app listens on port 12345 and I run my docker container with "-p 12345:5000" to redirect the port 12345 (from Docker container) to the port 5000 of my host. It works fine.
But when I run another Docker container with "-p 12345:50001", I have an error "Bind for 0.0.0.0:12345 failed: port is already allocated."
I don't understand why .. Thank you :)
You've mixed up your host and container ports!
The host port comes first and must be unique. The container port comes second. You probably want something like this, if your java apps both run on the same port in the container:
"-p 12345:50000"
"-p 12346:50000"
Or this if they really expose different ports in the container:
"-p 12345:50000"
"-p 12346:50001"

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.

How to assign as static port to a container?

I want to assign a container a port, so that it gets the same port after every restart of the container.
Example:
I have a container, which has an Apache in it. The Apache runs on port 80 inside the container.
Now, after starting the container, docker assigns a host port to the container port, for example: 49154 -> 80. But the host port changes after restart, depending on the number of running containers. I tried to specify the port in the config.json file of the container, but it gets overwritten.
Is it possible to specify the host port manually?
Thanks in advance and best regards,
Chris
Per the docker.io documentation: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/
$ sudo docker run -p 80:80 <image> <cmd>
Default port redirects can be built into a container with the EXPOSE build command.
When you start docker, you can use the '-p' parameter.
docker run -p 80 yourimage apache2 will do what you currently have.
Now, you can specify ':' to make this port static:
docker run -p :80 -p :443 yourimage apache2
If you are using a Dockerfile with the EXPOSE instruction, it is the same thing :)

Resources