Docker Course
Docker
/
Beginner

EXPOSE

Definition

An instruction that functions as a type of documentation, informing Docker that the container listens on specific network ports at runtime.

Explain Like I'm New

Putting a sign on the door that says 'I am a web server inside here, I will be listening on Port 80.' It doesn't actually open the door, it just tells humans and automated tools what to expect.

Real World Example

A Node.js backend runs on port 3000. You write `EXPOSE 3000` in the Dockerfile. When another developer looks at your file, they immediately know they need to map port 3000 when running it.

Common Use Cases

  • •Documentation
  • •Inter-container communication hints

Interview Questions

basic

  • Does the `EXPOSE 80` command actually publish the port to the public internet so you can view it in your browser?

Flash Cards

Question

Does it publish the port?

Click to reveal answer
Answer

NO. This is a massive misconception. `EXPOSE` does absolutely nothing mechanically. It does not open the firewall or map the port to your laptop. To actually publish the port, the user must use the `-p` flag (e.g., `-p 8080:80`) when running the `docker run` command.