Is it possible to set a different host port than the container's exposed port in docker?

6/3/2015

Is it possible to set a different host port than the container's exposed port in docker? For example docker run -name some_container -p 80:8080 -i -t some_img If so, is it -p host:container or -p container:host? I've looked through the docs and haven't found any examples of this nor details on the publish option for docker run.

Additionally, I don't want to use the same port as the container because that is where Kubernete's api-server is listening.

-- Christian Grabowski
docker
kubernetes
port
portforwarding

2 Answers

2/5/2019

Yes you can map any host port to container port unless it is being used by other application

docker run -p 80:8080 --name=centos centos:latest 

it is host:container format.

-- shubham_asati
Source: StackOverflow

6/3/2015

It is host:container and it is possible to set different port on the host. This Link has some good examples.

-- Chandan Nayak
Source: StackOverflow