1

I'm trying to develop a full-stack app with nodejs, react-native, expo and docker and when I try to make docker-compose down or docker-compose stop I get as status Exited(137) in frontend and backend but no in database and I don't understand why is this happening, I want the 3 of them finish correctly with status 0, here is my docker-compose and my dockerfiles:

docker-compose.yml:

version: '3.8'

services:
  back:
    build: ./backend # Esto le dice a Docker Compose dónde encontrar el Dockerfile (en el directorio actual)
    ports:
      - "3000:3000" # Mapea el puerto 3000 del contenedor al puerto 3000 de tu máquina local
    environment:
      - NODE_ENV=development # O cualquier otra variable de entorno que necesites
    volumes:
      - ./backend:/app
      - /app/node_modules
    depends_on:
      database:
        condition: service_healthy

  database:
      image: mysql:8.0.36
      #volumes: 
      #  - database:/data/db
      volumes:
      - ./backend/data/create_table.sql:/docker-entrypoint-initdb.d/create_table.sql
      ports:
        - 3306:3306
        - 33060:33060
      environment:
        - MYSQL_ROOT_PASSWORD=root
        - MYSQL_DATABASE=prueba
        - MYSQL_USER=user
        - MYSQL_PASSWORD=user
      healthcheck:
        test: ["CMD-SHELL", "mysql --user=user --password=user --database=prueba -e 'SELECT 1'"]
        interval: 10s
        timeout: 5s
        retries: 5
        start_period: 10s
  
  front:
    build: ./frontend
    volumes:
      - ./frontend:/app
      - /app/node_modules
    stdin_open: true # Equivalente a -i en docker run
    tty: true        # Equivalente a -t en docker run
    ports:
      - "8081:8081"
      - "19000:19000"
      - "19001:19001"
      - "19002:19002"
    environment:
      - NODE_ENV=development
      - EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
      - CHOKIDAR_USEPOLLING=true
    depends_on:
      - back

backend dockerfile:

# Elegir la versión de node.js a utilizar
FROM node:18-alpine3.19

# Establecer el directorio de trabajo en el contenedor
WORKDIR /app

# Copiar los archivos de configuración del proyecto (`package.json` y, opcionalmente, `package-lock.json`) al directorio de trabajo
COPY package*.json ./

# Instalar las dependencias del proyecto
RUN npm install

# Copiar el resto de los archivos del proyecto al directorio de trabajo
COPY . .

# Exponer el puerto en el que se ejecutará la aplicación
EXPOSE 3000

# Iniciar la app
CMD ["npm", "start"]

frontend dockerfile:

# Usamos la imagen base de Node.js
FROM node:18-alpine3.19

# Configura el directorio de trabajo dentro del contenedor
WORKDIR /app

# Copia el archivo package.json y package-lock.json (si existe)
COPY package*.json ./

# Instala las dependencias del proyecto
RUN npm install

# Copia los archivos del proyecto al contenedor
COPY . .

# Expo CLI utiliza el puerto 19000 por defecto
EXPOSE 8081
EXPOSE 19000
EXPOSE 19001
EXPOSE 19002

# Comando para iniciar la aplicación Expo
CMD ["npx", "expo", "start", "--tunnel"]

and my backend code just to show i don't have nothing implemented yet that may cause any problem:

const initDatabase = require('./data/sincro');
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

app.get('/', (req, res) => {
  res.send("Hola Mundoooo!");
});




// Manejar las señales de finalización del programa
process.on('SIGTERM', () => {
  console.log('SIGTERM signal received. Exiting.');
  server.close();
  process.exit(0);
});

process.on('SIGINT', () => {
  console.log('SIGINT signal received. Exiting.');
  server.close();
  process.exit(0);
});

// Inicializar la base de datos y luego iniciar el servidor
initDatabase().then(() => {
  server = app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
  });
});

I tried using init:true or tini in my dockerfiles but nothing works also handling the signals but in my local machine work everything correctly but no with docker

3
  • The volumes: blocks hide everything in your application images and replace them with a combination of host content and content from Docker named volumes. Does this potentially result in a wrong-architecture binary leaking into the container, or something with a missing C shared library? Does deleting volumes: from everywhere except the database container help? Commented Mar 6, 2024 at 21:00
  • Deleting the volumes made the docker-compose up faster but i still have the same problem with the exit status @DavidMaze Commented Mar 7, 2024 at 13:12
  • If i don't use nodemon in the backend i don't have that problem but i still have it in the frontend and i'm not using nodemon there is just a simple expo app Commented Mar 7, 2024 at 13:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.