Ravindra BagaleCourses & study guides

Chapter 6: Docker Images and Containers

6.5 Port publish -p — host port to container port

docker run -d --name badge-api -p 8080:8080 badge-api-hello:0.1
# host:container

Meaning: traffic that hits the host on counter 8080 goes to the container on counter 8080. You can map differently: -p 3000:8080 means host 3000 → container 8080.

Idea Reminder
Server / laptop IP The building address
Host port Shop counter on the building street side
Container port Counter inside the app box
EXPOSE Label on the box — not the street door

Safety. Publish only what you need. Do not publish database ports to the world on a public VM. For labs on a cloud VM, lock Security Groups the way the AWS course taught — we do not re-open VPC design here.

Ravindra Bagale's Tip

Khup students DB port -p 5432:5432 public VM var sodtat. Lab asel tari SG tight theva; prod madhe DB private network / non-public. Only required counters publish kara. Dhyan rakho!

Practice task

Explain -p 3000:8080 in one building/shop-counter sentence. Who knocks on 3000? Who listens on 8080?