You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/container-apps/java-containers-intro.md
+28-29Lines changed: 28 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: KarlErickson
5
5
ms.reviewer: craigshoemaker
6
6
ms.service: azure-container-apps
7
7
ms.topic: conceptual
8
-
ms.date: 04/15/2025
8
+
ms.date: 04/23/2025
9
9
ms.author: karler
10
10
ms.custom: devx-track-java
11
11
ai-usage: ai-generated
@@ -18,17 +18,17 @@ Containers provide a consistent, portable environment for your Java applications
18
18
In this article, you learn essential containerization concepts for Java developers and the following skills:
19
19
20
20
- Setting up your development environment for containerized Java applications.
21
-
- Creating **Dockerfiles** optimized for Java workloads.
21
+
- Creating Dockerfiles optimized for Java workloads.
22
22
- Configuring local development workflows with containers.
23
23
- Debugging containerized Java applications.
24
24
- Optimizing Java containers for production.
25
25
- Deploying your containerized Java applications to Azure Container Apps.
26
26
27
-
By containerizing your Java applications, you get consistent environments, simplified deployments, efficient resource utilization, and improved scalability.
27
+
By containerizing your Java applications, you get consistent environments, simplified deployment, efficient resource utilization, and improved scalability.
28
28
29
29
## Containers for Java applications
30
30
31
-
Containers package applications with their dependencies, ensuring consistency across environments. For Java developers, this means bundling the application, its dependencies, the Java Runtime Environment/Java Development Kit (JRE/JDK), and the configuration files into a single, portable unit.
31
+
Containers package applications with their dependencies, ensuring consistency across environments. For Java developers, this means bundling the application, its dependencies, the Java Runtime Environment/Java Development Kit (JRE/JDK), and configuration files into a single, portable unit.
32
32
33
33
Containerization has key advantages over virtualization that makes it 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 the Java virtual machine (JVM). Containerizing Java applications adds minimal overhead and provides significant deployment benefits.
34
34
@@ -52,10 +52,9 @@ To containerize Java applications, you need the following tools installed on you
52
52
-[Docker Desktop](https://www.docker.com/products/docker-desktop/). Provides the Docker engine, CLI, and Docker Compose for Windows or macOS.
53
53
-[Visual Studio Code](https://code.visualstudio.com/download). Available as a free code editor.
54
54
- The following Visual Studio Code extensions:
55
-
56
-
-[Docker extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) for managing containers.
57
-
-[Java Extension Pack](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) for Java development.
58
-
-[Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for developing inside containers.
55
+
-[Docker extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) for managing containers.
56
+
-[Java Extension Pack](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) for Java development.
57
+
-[Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for developing inside containers.
59
58
60
59
Verify your installation by using the following commands:
61
60
@@ -68,7 +67,7 @@ docker compose version
68
67
69
68
For Java development in containers, configure Visual Studio Code by installing the Java Extension Pack and setting up your JDK. The Dev Containers extension enables you to open any folder inside a container and use Visual Studio Code's full feature set inside that container.
70
69
71
-
Creating a **.devcontainer/devcontainer.json** file in your project enables Visual Studio Code to automatically build and connect to a development container.
70
+
To enable Visual Studio Code to automatically build and connect to a development container, create a **.devcontainer/devcontainer.json** file in your project.
72
71
73
72
For instance, the following example configuration defines a Java build:
74
73
@@ -95,10 +94,10 @@ This configuration uses Microsoft's Java development container image, adds essen
95
94
96
95
A **Dockerfile** contains instructions for building a Docker image. For Java applications, the **Dockerfile** typically includes the following components:
97
96
98
-
1. A base image with the JDK or JRE.
99
-
1. Instructions to copy application files.
100
-
1. Commands to set environment variables.
101
-
1. Configurations of entry points.
97
+
- A base image with the JDK or JRE.
98
+
- Instructions to copy application files.
99
+
- Commands to set environment variables.
100
+
- Configurations of entry points.
102
101
103
102
### Select a base image
104
103
@@ -127,7 +126,7 @@ EXPOSE 8080
127
126
ENTRYPOINT ["java", "-jar", "app.jar"]
128
127
```
129
128
130
-
For Spring Boot applications, you can set up your Dockerfile with the following base:
129
+
For Spring Boot applications, you can set up your **Dockerfile** with the following base:
docker run -p 8080:8080 -v ./data:/app/data myapp:latest
273
272
```
274
273
275
-
## Debugging containerized applications
274
+
## Debug containerized applications
276
275
277
276
Debugging containerized Java applications is sometimes challenging because your code runs in an isolated environment inside the container.
278
277
279
278
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.
280
279
281
280
### Set up remote debugging
282
281
283
-
Debugging containerized Java applications requires exposing a debug port and configuring your IDE to connect to it by using the following steps:
282
+
Debugging containerized Java applications requires exposing a debug port and configuring your IDE to connect to it. You can accomplish these tasks by using the following steps:
284
283
285
-
1. To enable debugging, modify your **Dockerfile** so it contains the following example:
284
+
1. To enable debugging, modify your **Dockerfile** so it contains the following content:
286
285
287
286
> [!NOTE]
288
287
> You can modify your container startup command, instead.
@@ -295,7 +294,7 @@ Debugging containerized Java applications requires exposing a debug port and con
@@ -351,15 +350,15 @@ The following table lists common issues and corresponding solutions:
351
350
352
351
## Optimize Java containers
353
352
354
-
Java applications in containers require special consideration for optimal performance. The JVM was designed before containers were common, which can lead to resource allocation issues if not properly configured.
353
+
Java applications in containers require special consideration for optimal performance. The JVM was designed before containers were common. Using containers can lead to resource allocation issues if they aren't properly configured.
355
354
356
-
By fine-tuning memory settings, optimizing the image size, and configuring garbage collection, you can significantly improve the performance and efficiency of your containerized Java applications. This section covers essential optimizations for Java containers, with a focus on memory management, startup time, and resource utilization.
355
+
You can significantly improve the performance and efficiency of your containerized Java applications by fine-tuning memory settings, optimizing the image size, and configuring garbage collection. This section covers essential optimizations for Java containers, with a focus on memory management, startup time, and resource utilization.
357
356
358
357
### JVM memory configuration in containers
359
358
360
359
The JVM doesn't automatically detect container memory limits in Java 8. For Java 9+, container awareness is enabled by default.
361
360
362
-
Configure your JVM to respect container limits by using the following example:
361
+
Configure your JVM to respect container limits, as shown in the following example:
363
362
364
363
```dockerfile
365
364
FROM mcr.microsoft.com/java/jre:21-zulu-ubuntu
@@ -387,7 +386,7 @@ This section covers the essential practices and configurations needed to prepare
387
386
388
387
Secure your containerized Java applications by using the following practices:
389
388
390
-
- Default security context. Run your applications as a non-root user by using the following example:
389
+
- Default security context. Run your applications as a non-root user, as shown in the following example:
391
390
392
391
```dockerfile
393
392
FROM mcr.microsoft.com/java/jre:21-zulu-ubuntu
@@ -413,7 +412,7 @@ Secure your containerized Java applications by using the following practices:
413
412
414
413
Check application health with [probes](health-probes.md) to ensure your application is running correctly.
415
414
416
-
For Spring Boot applications, include the Actuator dependency for comprehensive health endpoints by using the following XML example:
415
+
For Spring Boot applications, include the Actuator dependency for comprehensive health endpoints, as shown in the following example:
417
416
418
417
```xml
419
418
<dependency>
@@ -430,7 +429,7 @@ This section guides you through preparing your Java containers for Azure Contain
430
429
431
430
### Prepare your container for Azure
432
431
433
-
- Port configuration. Ensure your container listens on the port provided by Azure by using the following example:
432
+
- Port configuration. Ensure your container listens on the port provided by Azure, as shown in the following example:
0 commit comments