Dockerfile Expose Example Jun 2026
EXPOSE 53/udp # DNS service
EXPOSE does not actually open ports to the host machine or the outside world. It is a metadata label between the person who builds the image and the person who runs it. To actually make a port accessible from your laptop or the internet, you must use the -p (publish) flag when running the container. The Syntax The syntax is straightforward: dockerfile EXPOSE [ / ...] Use code with caution. Port: The number of the port (e.g., 80, 8080, 3000). dockerfile expose example
Once you have built this image (e.g., docker build -t my-web-app . ), you have two main ways to handle that exposed port. Option A: Explicit Mapping (Recommended) EXPOSE 53/udp # DNS service EXPOSE does not
WORKDIR /app
# Image EXPOSEs 3000, but we can run on different port internally docker run -p 8080:8080 -e PORT=8080 myapp The Syntax The syntax is straightforward: dockerfile EXPOSE