Bueno
Dejo un aporte para quien no haya usado intellijidea, como IDE, ya que, por motivos de licencia, según pude observar, tiene 30 días trial.
Realice la configuración mediante un devcontainer, dentro de visual studio code; es decir, sin instalar ninguna dependencia y que use docker como contenedor y despliegue de la aplicación para desarrollo.
devcontainer.json
// For format details, see For config options, see the
// README at:
{
"name": "Java & PostgreSQL",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
// Features to add to the dev container. More info:
// "features": {}
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or with the host.
// "forwardPorts": [5432],
"forwardPorts": [
8090,
5432
],
"portsAttributes": {
"8090": {
"label": "Spring Boot Application",
"onAutoForward": "openPreview", // This will open a browser preview
"protocol": "http"
},
"5432": {
"label": "Postgresql"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-containers",
"cweijan.vscode-postgresql-client2",
"ckolkman.vscode-postgres"
]
}
}
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "java -version",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info:
// "remoteUser": "root"
}
// For format details, see For config options, see the
// README at:
{
"name": "Java & PostgreSQL",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
// Features to add to the dev container. More info:
// "features": {}
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or with the host.
// "forwardPorts": [5432],
"forwardPorts": [
8090,
5432
],
"portsAttributes": {
"8090": {
"label": "Spring Boot Application",
"onAutoForward": "openPreview", // This will open a browser preview
"protocol": "http"
},
"5432": {
"label": "Postgresql"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-containers",
"cweijan.vscode-postgresql-client2",
"ckolkman.vscode-postgres"
]
}
}
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "java -version",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info:
// "remoteUser": "root"
}
// docker-compose.yml
version: '3.8'
volumes:
postgres-data:
services:
app:
container_name: javadev
build:
context: .
dockerfile: Dockerfile
environment:
# NOTE: POSTGRES_DB/USER/PASSWORD should match values in db container
POSTGRES_PASSWORD: alejandro.platzi
POSTGRES_USER: alejandro
POSTGRES_DB: platzi_play_db
POSTGRES_HOSTNAME: localhost
volumes:
- ../..:/workspaces:cached
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
db:
container_name: postgresdb
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- '5432:5432'
environment:
# NOTE: POSTGRES_DB/USER/PASSWORD should match values in app container
POSTGRES_PASSWORD: alejandro.platzi
POSTGRES_USER: alejandro
POSTGRES_DB: platzi_play_db
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
// Dockerfile
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
ARG INSTALL_MAVEN="false"
ARG MAVEN_VERSION=""
ARG INSTALL_GRADLE="true"
ARG GRADLE_VERSION=""
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
&& if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
Estos son los archivos de configuración para contenerizar una aplicación JAVA SpringBoot con postgresql
Ejecutan dentro del contenedor y luego ejecutan con el comando:
./gradlew bootRun
Y la aplicación funciona correctamente.