0
0
Dockerdevops~30 mins

EXPOSE instruction for ports in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the EXPOSE Instruction to Open Ports in Docker
📖 Scenario: You are creating a Docker image for a simple web application. To allow the application to communicate with the outside world, you need to open a specific port inside the container.
🎯 Goal: Learn how to use the EXPOSE instruction in a Dockerfile to open a port for your application.
📋 What You'll Learn
Create a Dockerfile with a base image
Add the EXPOSE instruction for a specific port
Build the Docker image
Run the container and verify the port is exposed
💡 Why This Matters
🌍 Real World
Opening ports in Docker containers is essential to allow applications inside containers to communicate with users or other services.
💼 Career
Understanding how to expose ports is a fundamental skill for DevOps engineers and developers working with containerized applications.
Progress0 / 4 steps
1
Create a Dockerfile with a base image
Create a file named Dockerfile and add a line to use the base image nginx:latest.
Docker
Need a hint?

The first line in a Dockerfile usually starts with FROM followed by the image name.

2
Add the EXPOSE instruction for port 80
Add a line to the Dockerfile to expose port 80 using the EXPOSE instruction.
Docker
Need a hint?

Use EXPOSE 80 to tell Docker to open port 80 inside the container.

3
Build the Docker image
Run the command docker build -t my-nginx . in your terminal to build the Docker image with the tag my-nginx.
Docker
Need a hint?

Open your terminal and run docker build -t my-nginx . to create the image.

4
Run the container and verify the port is exposed
Run the container with docker run -d -p 8080:80 --name webserver my-nginx and then run docker ps to check that port 8080 on your machine maps to port 80 in the container.
Docker
Need a hint?

Use docker run -d -p 8080:80 --name webserver my-nginx to start the container and docker ps to see the port mapping.