I am trying to setup an environment of three docker containers for a website. One for the frontend, one for the backend and one for the database.
Each one of these has a Dockerfile and I am building them all via the docker-compose up statement.
Now the express-backend container always throws following error:
songquiz_backend | internal/modules/cjs/loader.js:818
songquiz_backend | throw err;
songquiz_backend | ^
songquiz_backend |
songquiz_backend | Error: Cannot find module '/usr/src/app/app'
songquiz_backend | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
songquiz_backend | at Function.Module._load (internal/modules/cjs/loader.js:667:27)
songquiz_backend | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
songquiz_backend | at internal/main/run_main_module.js:17:47 {
songquiz_backend | code: 'MODULE_NOT_FOUND',
songquiz_backend | requireStack: []
songquiz_backend | }
songquiz_backend exited with code 1
This is what the Dockerfile looks like:
# Definieren des Basis Docker Images
FROM mongo-express
# Erstellen des Anwendungsverzeichnisses
WORKDIR /usr/src/app
# Kopieren der Konfigurationsdateien
# package.json und package-lock.json
COPY package*.json ./
# Installieren der Abhängigkeiten
RUN npm install
# Kopieren der Quelltextdateien
COPY . .
# Freigeben des Ports, unter dem der
# Express-Server läuft
EXPOSE 8080
# Starten des definierten npm-Scripts
CMD [ "node", "server.js" ]
# Alternativ Starten im Debug-Modus
# CMD [ "npm", "start:debug" ]
And this is the server.js:
'use strict';
const express = require('express');
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
I already tried deleting the node_modules folder in the project folder and reinstalling the modules via npm install.