liveBook · Manning

Port mapping

As explained in Build Python Web Apps with Streamlit

Container port mapping connects a port on the host machine to a port exposed by a Docker container.

Port mapping connects a port on the host machine to a port exposed by a Docker container. Because Streamlit runs inside the container while the browser runs on the host, the browser needs this forwarding route. section 12.2.5

Use the mapping syntax <port-on-host>:<port-on-container>:

  • Run the container with -p 8502:8501 when Streamlit listens on container port 8501. section 12.2.5
  • Open http://localhost:8502 in the browser; Docker forwards that host request to port 8501 inside the container. section 12.2.5
  • Change the host port when deployment requirements differ: Elastic Beanstalk uses 80:8501 so the application is reachable through standard HTTP port 80. section 12.3.5

Local container and cloud deployment

Start locally with docker run -p 8502:8501 fact-frenzy, then browse to localhost:8502. In docker-compose.yml for Elastic Beanstalk, replace the ports entry with "80:8501". section 12.2.5 section 12.3.5

docker run -p 8502:8501 fact-frenzy

Inspect the complete local docker run command that applies port mapping. section 12.2.5

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains host and container roles, command syntax, local access, and Elastic Beanstalk configuration without covering networking internals.
Examples
Uses 8502:8501 locally and 80:8501 for Elastic Beanstalk deployment.
What it assumes
Assumes a Docker image, running container, and application port; clarifies the host-versus-container distinction.
What you can do after
Operate a containerized Streamlit app locally and configure its exposed port for Elastic Beanstalk.
How it connects
Connects Docker containers, Streamlit, Docker Compose, and Elastic Beanstalk.

Also explained in

Compare how 2 books explain port mapping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.