Dockerfile Expose — Example
EXPOSE 3000 # This does NOT publish the port!
FROM node:18-alpine AS frontend WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 8080 USER node dockerfile expose example
FROM python:3.11 ENV APP_PORT=8000 EXPOSE $APP_PORT # Variable expansion works! EXPOSE 3000 # This does NOT publish the port
| Instruction | Scope | Function | | :--- | :--- | :--- | | | Inside Dockerfile | Defines which port is intended to be used inside the container network. | | -p (Publish) | During docker run | Actually maps a host port to a container port. | dockerfile expose example
EXPOSE 80 443