I'm not sure if I've misunderstood something here, but it seems like it's only possible to set port mappings by creating a new container from an image. Is there a way to assign a port mapping to an existing Docker container?
I'm also interested in this problem.
As @Thasmo mentioned, port forwardings can be specified ONLY with docker run
(and docker create
) command.
Other commands, docker start
does not have -p
option and docker port
only displays current forwardings.
To add port forwardings, I always follow these steps,
stop running container
docker stop test01
commit the container
docker commit test01 test02
NOTE: The above, test02
is a new image that I'm constructing from the test01
container.
re-run from the commited image
docker run -p 8080:8080 -td test02
Where the first 8080 is the local port and the second 8080 is the container port.