From cac702af43a127d280aa6485a2402bedb35492a0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 27 Mar 2025 17:56:44 -0600 Subject: [PATCH] docker, docker-compose, env example --- .env_example | 15 +++++++-------- Dockerfile | 23 +++++++++++++++++++++++ docker-compose.yml | 28 ++++++++++++++++++++++++++++ src/main.ts | 2 ++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env_example b/.env_example index 4465316..a56b453 100644 --- a/.env_example +++ b/.env_example @@ -1,15 +1,14 @@ -#Contraseñas Gmail +# Gmail USER_GMAIL= PASS_GMAIL= - # MariaDB database settings db_type=mysql -db_host=172.17.0.2 -db_username=root -db_database=ApiCorreos -db_password=mypass +db_host=mariadb # <-- uso del nombre del servicio, NO IP db_port=3306 +db_username=root # <-- te conectarás con root +db_password=mypass # <-- la misma que MARIADB_ROOT_PASSWORD +db_database=ApiCorreos -#Puero aplicación -PORT=3000 +# Puerto de la aplicación +PORT=4100 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9259854 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Etapa de construcción +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . +RUN npm run build + +# Etapa de producción +FROM node:20-alpine AS production + +WORKDIR /app + +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/package*.json ./ + +EXPOSE 4100 + +CMD ["node", "dist/main"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8b580e5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3.8' + +services: + mariadb: + image: mariadb:latest + container_name: mariadb-service + ports: + - "4101:3306" + environment: + MARIADB_ROOT_PASSWORD: mypass + MARIADB_DATABASE: ApiCorreos + volumes: + - mariadb_data:/var/lib/mysql + + api: + build: + context: . + dockerfile: Dockerfile + container_name: nestjs-api + env_file: + - .env + ports: + - "4100:4100" + depends_on: + - mariadb + +volumes: + mariadb_data: diff --git a/src/main.ts b/src/main.ts index 77262f1..11ff22b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,5 +18,7 @@ async function bootstrap() { SwaggerModule.setup('documentation', app, document); await app.listen(process.env.PORT ?? 3000); + + console.log(`Aplicación corriendo en: http://localhost:${process.env.PORT ?? 3000}`); } bootstrap();