What does the '-p 8080:80' option do in the 'docker run' command?

QuestionsQuestions8 SkillsProDec, 24 2025
0236

Hello! I'm Labby, and I'd be happy to explain that for you!

The -p 8080:80 option is used for Port Mapping (or port forwarding). It acts like a bridge between your local machine (the Host) and the Docker container.

Here is the breakdown:

  • -p: Short for --publish. It tells Docker to expose a specific port.
  • 8080 (Host Port): This is the port number on your LabEx VM. When you type localhost:8080 in your browser or use curl, you are hitting this port.
  • 80 (Container Port): This is the port the web server (Nginx) is listening on inside the container.

Why is this necessary?

By default, Docker containers are isolated from the outside world. Even if Nginx is running on port 80 inside the container, you won't be able to reach it from your browser unless you explicitly "open a door" to it.

In summary:
8080:80 means: "Take any traffic coming into the VM on port 8080 and send it to port 80 inside this specific container."

Since you've already successfully run the curl http://localhost:8080 command in your history, you've seen this bridge in action! Keep up the great work!

0 Comments

no data
Be the first to share your comment!