Skip to content

Commit 4bc07c9

Browse files
copy edit pass
1 parent b71d470 commit 4bc07c9

File tree

1 file changed

+50
-51
lines changed

1 file changed

+50
-51
lines changed

articles/container-apps/java-containers-intro.md

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ description: Learn the basics of using containers for Java applications.
44
services: container-apps
55
author: craigshoemaker
66
ms.service: azure-container-apps
7-
ms.custom: devx-track-azurecli, devx-track-extended-java
8-
ms.topic: tutorial
7+
ms.topic: conceptual
98
ms.date: 04/08/2025
109
ms.author: cshoe
1110
ai-usage: ai-generated
@@ -15,7 +14,7 @@ ai-usage: ai-generated
1514

1615
Containers provide a consistent, portable environment for your Java applications across development, testing, and production stages. This article introduces containerization concepts for Java applications and guides you through creating, debugging, optimizing, and deploying containerized Java applications to Azure Container Apps.
1716

18-
In this article, you'll learn about:
17+
In this article, you learn:
1918

2019
- Essential containerization concepts for Java developers
2120
- Setting up your development environment for containerized Java applications
@@ -25,22 +24,20 @@ In this article, you'll learn about:
2524
- Optimizing Java containers for production
2625
- Deploying your containerized Java applications to Azure Container Apps
2726

28-
By containerizing your Java applications, you get consistent environments, simplified deployment, efficient resource utilization, and improved scalability—all critical for modern cloud-native applications.
27+
By containerizing your Java applications, you get consistent environments, simplified deployment, efficient resource utilization, and improved scalability.
2928

3029
## Containers for Java applications
3130

3231
Containers package applications with their dependencies, ensuring consistency across environments. For Java developers, this means bundling the application, its dependencies, JRE/JDK, and configuration files into a single, portable unit.
3332

34-
Containers solve the "it works on my machine" problem by providing the same runtime environment everywhere.
35-
3633
Containerization has key advantages over virtualization that make them ideal for cloud development. In contrast to a virtual machine, a container runs on a server's host OS kernel. This is beneficial for Java applications which already run in a virtual machine (JVM). Containerizing Java applications adds minimal overhead while providing significant deployment benefits.
3734

3835
The container ecosystem includes several key components:
3936

4037
- images (the blueprints)
4138
- containers (running instances)
4239
- registries (where images are stored)
43-
- orchestrators (systems that manage containers at scale).
40+
- orchestrators (systems that manage containers at scale)
4441

4542
Docker is the most popular containerization platform, and is well-supported in the Azure ecosystem through Azure Container Apps.
4643

@@ -52,14 +49,14 @@ To containerize Java applications, you need several tools installed on your deve
5249

5350
1. **[Docker Desktop](https://www.docker.com/products/docker-desktop/)**: Provides the Docker engine, CLI, and Docker Compose for Windows or macOS.
5451

55-
1. **[Visual Studio Code](https://code.visualstudio.com/download)**: A lightweight but powerful code editor.
52+
1. **[Visual Studio Code](https://code.visualstudio.com/download)**: Available as a free code editor.
5653

57-
1. **Essential Visual Studio Code Extensions**:
54+
1. **Visual Studio Code extensions**:
5855
- [Docker extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) for managing containers
5956
- [Java Extension Pack](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) for Java development
6057
- [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension for developing inside containers.
6158

62-
After installing Docker Desktop, verify the installation with:
59+
After installing Docker Desktop, you can verify your installation with the following commands:
6360

6461
```bash
6562
docker --version
@@ -68,13 +65,11 @@ docker-compose --version
6865

6966
### Configure Visual Studio Code for container development
7067

71-
Visual Studio Code can dramatically improve your container development experience. The Docker extension provides syntax highlighting for Dockerfiles, command completion, and an explorer interface for managing containers.
72-
7368
For Java development in containers, configure Visual Studio Code by installing the Java Extension Pack and setting up your Java development kit. The *Dev Containers* extension enables you to open any folder inside a container and use Visual Studio Code's full feature set while inside that container.
7469

7570
Creating a `.devcontainer/devcontainer.json` file in your project allows Visual Studio Code to automatically build and connect to a development container.
7671

77-
For instance, the following configuration defines a Java build:
72+
For instance, the following example configuration defines a Java build:
7873

7974
```json
8075
{
@@ -110,12 +105,12 @@ Choosing the right base image is crucial. Consider these options:
110105

111106
| Description | Name | Remarks |
112107
|---|---|---|
113-
| **Microsoft Java development Image** | `mcr.microsoft.com/java/jdk:11-zulu-ubuntu` | Full JDK and optimized for Azure |
108+
| **Microsoft Java development Image** | `mcr.microsoft.com/java/jdk:11-zulu-ubuntu` | Full Java development kit (JDK) and optimized for Azure |
114109
| **Microsoft Java production Image** | `mcr.microsoft.com/java/jre:11-zulu-ubuntu` | Runtime only and optimized for Azure |
115110
| **Official OpenJDK development Image** | `openjdk:11-jdk` | Full JDK |
116111
| **Official OpenJDK production Image** | `openjdk:11-jre` | Runtime only |
117112

118-
For development environments, use a full JDK image. For production, use JRE or distroless images to minimize size and attack surface.
113+
For development environments, use a full JDK image. For production, use JRE or distroless images to minimize size and attack surface of your application.
119114

120115
The Microsoft Java images come with Azure-specific optimizations and are regularly updated with security patches, making them ideal for applications targeting Azure Container Apps.
121116

@@ -131,7 +126,7 @@ EXPOSE 8080
131126
ENTRYPOINT ["java", "-jar", "app.jar"]
132127
```
133128

134-
For Spring Boot applications, which are commonly used in microservices architecture, you can use setup your Dockerfile with the following base:
129+
For Spring Boot applications, you can setup your Dockerfile with the following base:
135130

136131
```dockerfile
137132
FROM mcr.microsoft.com/java/jdk:11-zulu-ubuntu
@@ -195,50 +190,54 @@ volumes:
195190
postgres-data:
196191
```
197192
198-
This configuration creates two containers: one for your Java application and one for a PostgreSQL database. It also sets up networking between them, mounts volumes for persistence, and exposes necessary ports.
193+
This configuration creates two containers: one for the Java application and one for a PostgreSQL database. It also sets up networking between them, mounts volumes for persistence, and exposes necessary ports.
199194
200195
## Debugging containerized applications
201196
202-
Debugging Java applications inside containers can be challenging because the code runs in an isolated environment. Standard debugging approaches don't directly apply, but with the right configuration, you can establish a remote debugging connection to containerized Java applications. This section shows you how to configure your containers for debugging, connect your development tools to running containers, and troubleshoot common container-related issues.
197+
Debugging containerized Java applications is sometimes challenging because your code runs in an isolated environment inside the container.
198+
199+
Standard debugging approaches don't always directly apply, but with the right configuration, you can establish a remote debugging connection to your application. This section shows you how to configure your containers for debugging, connect your development tools to running containers, and troubleshoot common container-related issues.
203200
204201
### Setting Up Remote Debugging
205202
206203
Debugging containerized Java applications requires exposing a debug port and configuring your IDE to connect to it:
207204
208205
1. To enable debugging, modify your Dockerfile or container startup command:
209206
210-
```dockerfile
211-
FROM mcr.microsoft.com/java/jdk:11-zulu-ubuntu
212-
WORKDIR /app
213-
COPY target/*.jar app.jar
214-
EXPOSE 8080 5005
215-
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar", "app.jar"]
216-
```
207+
```dockerfile
208+
FROM mcr.microsoft.com/java/jdk:11-zulu-ubuntu
209+
WORKDIR /app
210+
COPY target/*.jar app.jar
211+
EXPOSE 8080 5005
212+
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar", "app.jar"]
213+
```
217214

218215
1. Configure Visual Studio Code's `launch.json` to connect to the debug port:
219216

220-
```json
221-
{
222-
"version": "0.2.0",
223-
"configurations": [
217+
```json
224218
{
225-
"type": "java",
226-
"name": "Debug in Container",
227-
"request": "attach",
228-
"hostName": "localhost",
229-
"port": 5005
219+
"version": "0.2.0",
220+
"configurations": [
221+
{
222+
"type": "java",
223+
"name": "Debug in Container",
224+
"request": "attach",
225+
"hostName": "localhost",
226+
"port": 5005
227+
}
228+
]
230229
}
231-
]
232-
}
233-
```
230+
```
234231

235232
1. Start your container with port `5005` mapped to your host, then launch the debugger in Visual Studio Code.
236233

237234
### Troubleshooting Container Issues
238235

239236
When containers don't behave as expected, you can inspect your app's logs to investigate the issue.
240237

241-
Use the following commands to troubleshoot your app. Before you run these commands, make sure to replace the placeholders surrounded by `<>` with your own values.
238+
You can use the following commands to troubleshoot your application.
239+
240+
Before you run these commands, make sure to replace the placeholders surrounded by `<>` with your own values.
242241

243242
```bash
244243
# View logs
@@ -262,12 +261,12 @@ ENTRYPOINT ["java", "-XX:+PrintFlagsFinal", "-XX:+PrintGCDetails", "-jar", "app.
262261

263262
Common issues include:
264263

265-
| Error | Task |
264+
| Error | Possible solution |
266265
|---|---|
267266
| Out of memory | Increase container memory limits |
268-
| Connection time-outs | Check network configuration |
269-
| Permission problems | Verify file system permissions |
270-
| Classpath issues | Check JAR structure and dependencies |
267+
| Connection time-outs | Check network configuration for errors. Verify ports and routing rules. |
268+
| Permission problems | Verify file system permissions. |
269+
| Classpath issues | Check JAR structure and dependencies. |
271270

272271
## Optimizing Java Containers
273272

@@ -308,7 +307,7 @@ This section covers the essential practices and configurations needed to prepare
308307

309308
Secure your containerized Java applications with these practices:
310309

311-
- **Default security context**: Run as non-root user:
310+
- **Default security context**: Run your application as a non-root user:
312311

313312
```dockerfile
314313
FROM mcr.microsoft.com/java/jre:11-zulu-ubuntu
@@ -319,19 +318,19 @@ Secure your containerized Java applications with these practices:
319318
ENTRYPOINT ["java", "-jar", "app.jar"]
320319
```
321320

322-
- **Proactively look for issues**: Scan images for vulnerabilities:
321+
- **Proactively look for issues**: Regularly scan container images for vulnerabilities:
323322

324323
```bash
325324
docker scan myapp:latest
326325
```
327326

328-
- **Base image freshness**: Use up-to-date base images.
327+
- **Base image freshness**: Keep your base images up-to-date.
329328

330-
- **Secrets management**: Implement proper secrets management (don't hardcode sensitive data)
329+
- **Secrets management**: Implement proper secrets management. For instance, don't hardcode sensitive data into your application and use a Key Vault whenever possible.
331330

332-
- **Restricted security contexts**: Apply the principle of least privilege
331+
- **Restricted security contexts**: Apply the principle of least privilege to all security contexts.
333332

334-
- **File system access**: Use read-only file systems where possible
333+
- **File system access**: Use read-only file systems wherever possible.
335334

336335
### Health checks and monitoring
337336

@@ -365,11 +364,11 @@ This section guides you through preparing your Java containers for Azure Contain
365364
CMD java -jar app.jar --server.port=${PORT}
366365
```
367366

368-
1. **Probe for health**: Implement health probes for Azure's liveness and readiness checks
367+
- **Probe for health**: Implement [health probes](health-probes.md) for Azure's liveness and readiness checks
369368

370-
1. **Log configuration**: Configure logging to output to `stdout`/`stderr`
369+
- **Log configuration**: Configure logging to output to `stdout`/`stderr`.
371370

372-
1. **Plan for the unexpected**: Set up proper graceful shutdown handling with time out configuration
371+
- **Plan for the unexpected**: Set up proper graceful shutdown handling with time out configuration
373372

374373
## Related content
375374

0 commit comments

Comments
 (0)