liveBook · Manning

Container

As explained in Build Financial Software with Generative AI (From Scratch)

A container is an isolated runtime unit that packages an application with its dependencies and executes it using shared operating-system facilities.

A container is an isolated environment for running one part of an application. Docker makes containers practical for a dashboard with several moving parts: a Next.js interface, a FastAPI service, and a PostgreSQL database can each run separately. This keeps the components organized and lets them evolve independently without installing every service directly on the host machine. section 3.1 section 3.9

Build a multicontainer application in small, testable steps:

  • Start one container before configuring the entire system. A generated Compose file may be a useful starting point, but verify it rather than assuming it works. section 3.2
  • Declare services together in docker-compose.yml, then check that the interface can reach the API and the API can reach the database. section 3.2 section 3.3
  • Record host and internal ports. A service may need an internal port without exposing a port on the host. section 3.3
Table 3.1 Container port listing

Container name

Host port

Internal port

CloudBeaver

8080

8080

Postgres

-

5432

Api

8000

8000

Web

3000

80

This information is also available in the docker-compose file, but sometimes it is easier to have a reference sheet. Note that, currently, we are not exposing a Host Port for Postgres. In the next section, we’ll dig a little deeper to see why.

The port table distinguishes host ports from internal ports for the web, API, database, and database-management containers. section 3.3

When the API cannot reach PostgreSQL

Check the output of docker-compose up for an earlier startup error. Then inspect the API code, requirements.txt, and Dockerfile for missing dependencies or failures. In a container-to-container connection string, use the database container’s name rather than localhost; also check that the configured credentials match. section 3.3.2

A running container is not necessarily healthy. Docker health checks can report starting, healthy, or unhealthy status; docker ps displays that status when a health check is configured. For PostgreSQL, a Dockerfile health check can run pg_isready with the configured database user. Health information supports monitoring and can inform restart behavior. section 3.8

Container configuration also matters when adding the dashboard. Its Dockerfile builds and starts the Next.js application, while a Compose build argument supplies NEXT_PUBLIC_API_URL. Because the dashboard’s API request runs in the browser, that URL uses the browser-accessible endpoint rather than an internal container address. Containers are useful beyond deployment: a disposable Docker image can provide a quick sandbox for trying another product. section 6.8 section 12.2.1

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Works through Compose setup, connectivity, troubleshooting, and health checks, but stops short of Docker expertise.
Examples
Uses separate Next.js, FastAPI, and PostgreSQL services, a port table, connection errors, and a PostgreSQL health check.
What it assumes
Starts from no Docker experience and introduces a single container before attempting a multicontainer configuration.
What you can do after
Operate/configure it with Docker Compose to connect services, investigate startup failures, and check container health.
How it connects
Connects containers to Docker Compose, service-oriented architecture, networking, health checks, and microservices.

Also explained in

Compare how 29 books explain container →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.