Demonstration of How to Do Port Mapping in Docker
- Sharon Rajendra Manmothe

- 6 hours ago
- 1 min read
STEP 1: Run NGINX on Port 8080
docker run -d --name mynginx -p 8080:80 nginx
NGINX is running inside container on port 80✔ You are accessing it from host on 8080
Test:
STEP 2: Try to Reassign the SAME HOST PORT (8080) to Another Container
Now run:
docker run -d --name mynginx2 -p 8080:80 nginx
You will get an error:
Error starting userland proxy: listen tcp4 0.0.0.0:8080: bind: address already in use
Meaning:
Port 8080 on your machine is already occupied by mynginx
Docker cannot assign the same host port twice
This demonstrates port conflict.
STEP 3: Check Which Container Is Using Port 8080
Run:
docker ps
You will see:
0.0.0.0:8080->80/tcp mynginx
STEP 4: Free Port 8080
Stop the container:
docker stop mynginx
Remove the container:
docker rm mynginx
Port 8080 is now free.
STEP 5: Run New Container Again on Port 8080
docker run -d --name mynginx2 -p 8080:80 nginx
✔ This time it works✔ Because port 8080 is free
Test:
STEP 6: Reassign to a NEW PORT Instead (Optional)
If the old port is busy, assign another port:
docker run -d --name mynginx3 -p 9000:80 nginx
Test:
What You Have Demonstrated
Concept | Explanation |
Port Binding | -p HOST:CONTAINER |
Port Conflict | Same host port cannot be used twice |
Port Release | Stop/remove container to free port |
Port Reassignment | Assign a new port like 9000 |

$50
Product Title
Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button

$50
Product Title
Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

$50
Product Title
Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.



Comments