Docker Desktop
Features: Provides a local Docker engine, CLI, and graphical dashboard for viewing images, containers, and logs.
Later use: Run and troubleshoot containers locally during development.
Understand Docker fundamentals and Java REST API flow through diagrams and examples.
Docker helps you package an application and the files it needs into an image. You can use that image to start an isolated process called a container. This makes setup and delivery more repeatable across development and deployment environments.
Unlike a traditional virtual machine, a Linux container shares the host's Linux kernel instead of running a separate guest operating system. On Windows, Docker Desktop runs Linux containers using a Linux environment.
docker --version
docker info
docker --version prints the CLI version. docker info should also show server information. If it cannot connect to the engine, start Docker Desktop and try again.
The Docker client sends your commands to the Docker engine. The engine manages images, containers, and networks, and downloads images from a registry when needed.
An image is built from Dockerfile instructions and a build context. It can be tagged, pushed to a registry, and used to create multiple containers.
Rebuilding an image does not change an existing container. Create a new container to use the new version. Use separate storage such as a volume for persistent data.
Port mapping connects a port on your computer to a port in the container. Below, the web server listens on port 80 inside the container.
This optional command starts a container from the public Nginx image. It needs internet to download the image; press Ctrl+C to stop it. --rm removes the container after it stops.
docker run --rm --name a143mk-nginx -p 127.0.0.1:8080:80 nginx:alpine
127.0.0.1 limits access to your computer. If 8080 is busy, map another free host port to port 80.Use these commands to inspect images and containers:
docker image ls
docker ps
docker ps -a
docker image ls lists local images.docker ps lists running containers; docker ps -a also includes stopped containers.docker logs a143mk-nginx shows logs while the example container exists.These tools help you build, share, and inspect containers. Here are their key features and how they fit into later lessons.
Features: Provides a local Docker engine, CLI, and graphical dashboard for viewing images, containers, and logs.
Later use: Run and troubleshoot containers locally during development.
Features: Manage Docker using commands such as docker build, docker run, and docker logs.
Later use: Automate builds and checks in terminals and CI/CD pipelines.
Features: An image registry for sharing images through public or private repositories.
Later use: Publish images built in CI and pull them for deployment.
Features: Define and manage multiple services, networks, and volumes together with YAML configuration.
Later use: Run a Java API and database together for local development.
Features: Offers advanced BuildKit-based builds, including multi-platform images.
Later use: Build images for different CPU architectures in CI with an appropriate builder setup.
Features: Helps analyze image packages for known vulnerabilities and review remediation options.
Later use: Review image risks before delivery; scanning does not guarantee security.
Imagine a Java REST API running inside a Docker container. A client sends an HTTP request and the API returns a JSON response.
@RestController maps a Java class to HTTP endpoints. This is an illustration of a Spring Boot controller; running it requires a Spring Boot application and its dependencies.
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
class HelloController {
@GetMapping("/api/hello")
public Map<String, String> hello() {
return Map.of("message", "Hello from Java!");
}
}
Interactive illustration: Press the button to see an example response. This is a browser simulation; no real API request is sent.
docker info.127.0.0.1:8081:80, and visit http://localhost:8081.docker ps -a and choose a different name for the example.docker logs a143mk-nginx for errors. With --rm, it is removed when it stops.Choose an answer for each question and check your results.
You have explored Docker images, containers, port mapping, and Java API flow. Next, learn how Kubernetes manages containerized applications and how CI/CD automates building and delivering them.
Continue learning with the official Docker getting-started guide.
Understand Docker images, Dockerfiles, volumes, and Compose with diagrams and examples.
In Part 1, we learned that an image is a packaged template and a container is an instance of it. In this part, we explore how images are built and how multiple services work together.
An image is made of layers. During a build, Docker can reuse cached results for unchanged steps, which can make repeated builds faster.
Interactive example: See the build stages. This is a browser simulation; it does not run Docker.
This illustrative Dockerfile packages a Java REST API. It assumes an executable Java 17-compatible JAR already exists in the build context at target/app.jar. It is a code illustration, not a complete Java project.
FROM eclipse-temurin:17-jre
WORKDIR /app
COPY target/app.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
FROM selects a base runtime image and WORKDIR sets the working directory.COPY places the JAR from the build context into the image.EXPOSE documents the intended container port; it does not publish it. ENTRYPOINT starts the Java application.A tag identifies an image name and version, such as my-api:1.0. A registry stores images for sharing. Tags can be moved; an image digest provides a more precise identifier.
docker image ls lists local images. Before pushing, check the target repository and required permissions.
Data in a container's writable layer is lost when that container is removed. A Docker volume can keep data separate from the container's lifecycle.
Compose uses YAML to define multiple services as one application. The configuration below illustrates two separate services; Nginx does not automatically use Redis.
services:
web:
image: nginx:alpine
ports:
- "127.0.0.1:8080:80"
cache:
image: redis:7-alpine
With a Compose configuration, docker compose up starts services and docker compose down stops them and removes their containers and networks. Use volume-removal options carefully.
Properly configured containers can reach one another by service name on the default Compose network, such as cache:6379.
A typical Java API receives a request, reads data from a database, and returns JSON. Containerization does not automatically make the application secure or scalable.
The actual API port, database connection, authentication, and health checks depend on the application's configuration. This diagram illustrates the concept only.
The build context contains the files available to the builder. Including only what is needed can speed up builds and reduce accidental exposure of unnecessary data.
These are example .dockerignore patterns. Check them against your project: the Dockerfile above needs target/app.jar, so do not exclude the entire target directory.
.git
.env
*.log
When a step's inputs change, it and dependent later steps may need to run again. Placing less frequently changed steps before frequently changed application code can improve cache reuse.
A multi-stage Dockerfile can separate build and runtime stages. Copying only the required artifact into the final image can make it smaller without including build tools.
Read more: build context, multi-stage builds, and build secrets.
Application settings may differ between development, test, and production. Pass non-sensitive settings at runtime; use your environment's secret manager for passwords and API keys.
db:5432. Inside a container, localhost refers to that container.The example db address works only when that Compose project has a database service named db. The Nginx/Redis example above does not define one.
In these commands, a143mk-docker2-nginx is an example container name. Run them only against your own container; choose another name if it is already in use.
For an optional local test, start Docker, make sure internet is available and port 8080 is free. This starts a background container from the public Nginx image:
docker run -d --name a143mk-docker2-nginx -p 127.0.0.1:8080:80 nginx:alpine
While it is running, open http://localhost:8080; you should see the Nginx welcome page. In another terminal, inspect status, logs, and port mapping. The container must be running to view resource usage.
docker ps -a
docker logs --tail 50 a143mk-docker2-nginx
docker inspect --format '{{.State.ExitCode}}' a143mk-docker2-nginx
docker port a143mk-docker2-nginx
docker stats --no-stream a143mk-docker2-nginx
If you started the container above and no longer need it, stop and remove only that container:
docker stop a143mk-docker2-nginx
docker rm a143mk-docker2-nginx
docker compose ps shows status and docker compose logs shows service logs.Before sharing an image with your team or CI/CD pipeline, consider these points:
Choose an answer for each question and check your results.
You have explored image layers, Dockerfiles, volumes, and Compose. Next, learn Kubernetes fundamentals and how containers are deployed.
Learn more: Dockerfile documentation and Docker Compose documentation.
Learn secure Kubernetes delivery, rollouts, and rollbacks from registry images.
Part 5 covered CI pipelines, Docker image builds, and HTTP smoke tests. This part delivers that artifact into a cluster safely.
A CD pipeline should not rebuild an image that was already verified. Promote an immutable digest from the registry so staging and production run the exact same artifact.
kubectl config current-context and kubectl get ns first identify the target cluster and namespace.kubectl config current-context
kubectl auth can-i get pods -n a143mk-demo
kubectl auth can-i create deployments -n a143mk-demo
kubectl auth can-i update deployments -n a143mk-demo
kubectl -n a143mk-demo get deployment,service
This example uses a digest placeholder. A real workflow replaces the placeholder before applying the manifest.
apiVersion: apps/v1
kind: Deployment
metadata:
name: a143mk-api
namespace: a143mk-demo
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: a143mk-api
template:
metadata:
labels:
app: a143mk-api
spec:
containers:
- name: api
image: ghcr.io/YOUR_ACCOUNT/a143mk-api@sha256:REPLACE_WITH_DIGEST
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
---
A liveness probe restarts the container; a readiness probe stops traffic. Probe failures may indicate an application problem. Configure a valid health endpoint and realistic startup time.
This is a design example, not a copy-and-run workflow. Adapt credentials, registry, cluster, and manifests for your environment and obtain organizational approval first.
name: Promote and deploy API
on:
workflow_dispatch:
inputs:
image_digest:
description: "Verified sha256 digest"
required: true
type: string
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
timeout-minutes: 15
steps:
- name: Check out deployment manifests
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install a pinned kubectl
run: echo "Configure the approved kubectl installation here"
- name: Select only your deployment context
run: |
echo "Configure a short-lived kube credential before this step"
kubectl config current-context
- name: Substitute image digest
run: |
test "${{ inputs.image_digest }}" =~ ^sha256:[a-f0-9]{64}$
sed -i "s|sha256:REPLACE_WITH_DIGEST|${{ inputs.image_digest }}|" k8s/deployment.yaml
- name: Apply and verify
run: |
kubectl -n a143mk-demo apply -f k8s/deployment.yaml
kubectl -n a143mk-demo rollout status deployment/a143mk-api --timeout=300s
A tag is convenient but mutable. An immutable digest in repo@sha256:... identifies one exact image manifest.
# Ask the registry for the digest of an already-published image.
docker buildx imagetools inspect ghcr.io/YOUR_ACCOUNT/a143mk-api:v1.2
# Record the immutable digest in your release record.
# Example manifest:
# image: ghcr.io/YOUR_ACCOUNT/a143mk-api@sha256:64_HEX_CHARACTERS
After apply, inspect rollout status and test the service's real HTTP health. kubectl rollout status waits for completion, while an endpoint test verifies behavior separately.
kubectl -n a143mk-demo rollout status deployment/a143mk-api --timeout=300s
kubectl -n a143mk-demo get deployment a143mk-api
kubectl -n a143mk-demo get pods -l app=a143mk-api
kubectl -n a143mk-demo rollout history deployment/a143mk-api
kubectl -n a143mk-demo run a143mk-curl \
--image=curlimages/curl:latest \
--restart=Never \
--rm -i -- curl --fail --silent --show-error \
http://a143mk-api:8080/health
Roll back to a known-good digest or previous revision. Rollback changes only the Kubernetes workload; database schemas, external APIs, and data migrations do not revert automatically.
kubectl -n a143mk-demo rollout history deployment/a143mk-api
kubectl -n a143mk-demo rollout undo deployment/a143mk-api
kubectl -n a143mk-demo rollout status deployment/a143mk-api --timeout=300s
kubectl -n a143mk-demo get deployment a143mk-api -o wide
Define a clear release-halt rule: inspect health, metrics, and logs, then roll back according to an approved team decision.
In GitOps, a Git repository is the source of desired state. A controller observes repository changes and reconciles Kubernetes.
Common structure:
gitops-repository/
environments/
staging/
kustomization.yaml
deployment-patch.yaml
production/
kustomization.yaml
deployment-patch.yaml
Helm packages releases with templates, values, and charts. Raw manifests are simpler; use Helm when reusable templates are genuinely needed.
kubectl -n a143mk-demo describe deployment/a143mk-api
kubectl -n a143mk-demo get pods -l app=a143mk-api
kubectl -n a143mk-demo logs -l app=a143mk-api --tail=100
kubectl -n a143mk-demo get endpoints a143mk-api
kubectl -n a143mk-demo get events --sort-by=.lastTimestamp