19 · Operations and deployment foundations / LESSON 95 OF 102
Package and containerize
Deploy the same artifact with external configuration.
Before this lesson: Logs, health, and performance
Understand the topic
Run ./mvnw clean verify. Set Maven build finalName to tasks-api for this Dockerfile or change COPY to your actual jar name. Use a compatible Java runtime and supply secrets when running the container, not while building the image.
Use HTTPS at ingress, private database access, non-root execution, backups, and resource limits. Persistent data belongs outside the application container. Hosting is not provisioned by this course.
EXAMPLE · DOCKERFILE
Dockerfile · project root
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/tasks-api.jar app.jar
USER 10001:10001
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]What to expect
After building the named jar, run docker build -t tasks-api . and provide datasource settings at runtime.
YOUR TURN
Put it into practice
- 01Run locally with port 8080 mapped.
- 02Check the process is non-root and secrets are absent from the image.
- 03Replace the container and verify persisted tasks remain.
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
An image packages the runtime and artifact; deployment supplies configuration, networking, and persistent services.
- 01Containers are replaceable. Store persistent data in a database or volume with a backup plan, not in the application container filesystem.
- 02Use a non-root process and grant only necessary filesystem access. Scan and update base images; pin release artifacts so rollbacks are reproducible.
- 03CI should build and test once, then promote the same artifact. Rebuilding differently for each environment undermines that guarantee.
A mistake worth avoiding
Never copy local secret files into an image layer.
DEBUGGING ROOM
Something broke. Where do you look?
Tasks disappear when the application container is replaced.
Before revealing the diagnosis, write down your first investigation step.
CHECK YOUR UNDERSTANDING
Which should change between staging and production?
BUILD IT YOURSELF
Rehearse a release and rollback
- 1.Build a tagged image from a tested commit.
- 2.Run with external configuration and persistent database storage.
- 3.Replace with a new version, then roll back the app artifact.
Acceptance checklist
Lab completion is your self-report. Knowledge checks do not certify project quality.
RETRIEVE IT FROM MEMORY
Which schema changes can make an application rollback unsafe?
Revisit this lesson in three days after a successful check or lab.
Ready for the next step?
Explain jar, image, container, and persistent storage.
Reading is separate from passing a knowledge check or completing a lab.