Docker Community Forums

Share and learn in the Docker community.

How to change port of an docker image


(Goodyoneloves) #1

Hi,

I have done docker pull of two images, apparently both run on same port 8080. One of the image is https://hub.docker.com/r/webgoat/webgoat-7.1/

I followed steps and did docker pull and when I run the container on but with port 8081:8081 it still maps to 8080.

I have another container running on 8080, and would like to run webgoat on different port. Since I have downloaded webgoat docker image I don’t have access to dockerfile to change ports. Any inputs on this will be really helpful.


(David Maze) #2

Can you share your exact docker run command, and why you think there’s a port conflict?

Usually the program in an image will always listen on a fixed port, and that’s okay. docker run -p takes a host port and a container port number, and these can be different. You should be able to run something like

docker run -d -p 8080:8080 --name one webgoat/webgoat-7.1:latest
docker run -d -p 8081:8080 --name two webgoat/webgoat-7.1:latest

If you look at docker logs two it might say it’s listening on 0.0.0.0:8080. That’s okay; host port 8081 will still route there.


(Goodyoneloves) #3

Thanks for response, I was playing around with docker command and accidentally figured out docker run -d -p 8081:8080 --name two webgoat/webgoat-7.1 would be right way to map same docker image on different port.