Dockerfile Expose Example < macOS >

FROM python:3.11 ENV APP_PORT=8000 EXPOSE $APP_PORT # Variable expansion works!

COPY . .

# View exposed ports from image docker image inspect myapp --format='json .Config.ExposedPorts' dockerfile expose example

EXPOSE 8000/tcp # Main web application EXPOSE 8080/tcp # Admin interface EXPOSE 5432/tcp # Internal database (documentation only) FROM python:3

If you are using Docker Compose, the expose and ports keys behave similarly to the Dockerfile instructions, but with a twist regarding networking. dockerfile expose example

# Build stage FROM golang:1.21 AS builder WORKDIR /src COPY . . RUN go build -o myapp

version: '3.8' services: web: build: . expose: - "3000" # Internal (EXPOSE equivalent) - "8080" ports: - "80:3000" # Actual port mapping - "8080:8080"