Loading published curriculum…

20 · Production engineering and architecture / LESSON 97 OF 102

Docker builds, networking, and persistent data

A container packages a process environment; its network and filesystem are not your host’s defaults.

Before this lesson: CI pipelines and artifact promotion

Understand the topic

localhost inside an application container refers to that container. Use a configured service name or host address to reach the database. Store database data in managed persistent storage or a volume and test restore procedures.

Use a non-root runtime, keep the image small, and exclude secrets and build caches from the context. Readiness should prevent traffic before startup dependencies are usable. Image tags should identify a tested release rather than an ambiguous latest build.

EXAMPLE · DOCKERFILE

Dockerfile

FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/task-api.jar /app/app.jar
USER 10001:10001
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

What to expect

Set the Maven final artifact name to task-api.jar or adjust COPY. Pin the base image digest for a controlled release and supply configuration at runtime.

YOUR TURN

Put it into practice

  1. 01Run the application and PostgreSQL on a dedicated container network.
  2. 02Replace the application container and verify records survive; inspect the image for copied secret files.
  3. 03Verify: Database state persists independently and the application process runs as a non-root user.

Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.

UNDER THE HOOD

Build the mental model

A container packages a process environment; its network and filesystem are not your host’s defaults.

  1. 01localhost inside an application container refers to that container. Use a configured service name or host address to reach the database. Store database data in managed persistent storage or a volume and test restore procedures.
  2. 02Use a non-root runtime, keep the image small, and exclude secrets and build caches from the context. Readiness should prevent traffic before startup dependencies are usable. Image tags should identify a tested release rather than an ambiguous latest build.
  3. 03Trace the example: Set the Maven final artifact name to task-api.jar or adjust COPY. Pin the base image digest for a controlled release and supply configuration at runtime.

A mistake worth avoiding

A containerized app cannot reach a database configured as localhost.

DEBUGGING ROOM

Something broke. Where do you look?

A containerized app cannot reach a database configured as localhost.

Before revealing the diagnosis, write down your first investigation step.

CHECK YOUR UNDERSTANDING

Does localhost inside a container automatically refer to the host machine?

Choose one answer

BUILD IT YOURSELF

Run the application and PostgreSQL on a dedicated container network.

  1. 1.Run the application and PostgreSQL on a dedicated container network.
  2. 2.Replace the application container and verify records survive; inspect the image for copied secret files.
  3. 3.Reproduce this failure, then repair it: A containerized app cannot reach a database configured as localhost.

Acceptance checklist

Lab completion is your self-report. Knowledge checks do not certify project quality.

RETRIEVE IT FROM MEMORY

Does localhost inside a container automatically refer to the host machine?

Revisit this lesson in three days after a successful check or lab.

Ready for the next step?

Database state persists independently and the application process runs as a non-root user.

Reading is separate from passing a knowledge check or completing a lab.

Go deeper · official references