Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 32 / 45

Declaring Ports with EXPOSE

When you want to document which port your application listens on, use EXPOSE. It declares the port the container intends to use.

The syntax is EXPOSE port.

Writing EXPOSE 80 records that the container serves on port 80, which anyone reading the Dockerfile can see immediately.

A common stumble is expecting EXPOSE to publish the port. It does not — it is documentation. Actually reaching the port still requires -p at run time.

In real work, it makes a Dockerfile self-describing and lets tools such as Docker Compose act on the declared ports.

Docker
Try it (type this into the pseudo terminal)
docker build -t myapp .

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)