Develop applications with Java and PostgreSQL. Includes a Java application container and PostgreSQL server.
| Options Id | Description | Type | Default Value |
|---|---|---|---|
| imageVariant | Java version (use -bullseye variants on local arm64/Apple Silicon): | string | 17-bullseye |
| installMaven | Install Maven, a management tool for Java | boolean | false |
| installGradle | Install Gradle, a build automation tool for multi-language software development | boolean | false |
| nodeVersion | Node.js version: | string | lts/* |
This template creates two containers, one for Java and one for PostgreSQL. VS Code will attach to the Java container, and from within that container the PostgreSQL container will be available on localhost port 5432. The default database is named postgres with a user of postgres whose password is postgres, and if desired this may be changed in .devcontainer/docker-compose.yml. Data is stored in a volume named postgres-data.
While the template itself works unmodified, it uses the mcr.microsoft.com/devcontainers/java image which includes git, a non-root vscode user with sudo access, and a set of common dependencies and Java tools for development.
You also can connect to PostgreSQL from an external tool when using VS Code by updating .devcontainer/devcontainer.json as follows:
"forwardPorts": [ "5432" ]Once the PostgreSQL container has port forwarding enabled, it will be accessible from the Host machine at localhost:5432. The PostgreSQL Documentation has:
- An Installation Guide for PSQL a CLI tool to work with a PostgreSQL database.
- Tips on populating data in the database.
If needed, you can use postCreateCommand to run commands after the container is created, by updating .devcontainer/devcontainer.json similar to what follows:
"postCreateCommand": "java -version && git --version && node --version"You can add other services to your .devcontainer/docker-compose.yml file as described in Docker's documentation. However, if you want anything running in this service to be available in the container on localhost, or want to forward the service locally, be sure to add this line to the service config:
# Runs the service on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:dbNote: This file was auto-generated from the devcontainer-template.json. Add additional notes to a NOTES.md.