Hello, I’m a bit new here and signed up just because of this issue I’m having and busting my head because of it…
I am totally new to docker and docker compose (ofc), started a few days ago with docker in general.
So the issue I’m having is as follows;
I have one root folder for a project which includes the app and server.
docker-compose.yml
\_ server
\_ dockerfile
\_ package.json
\_ index.js
\_ ...
\_ app
\_ dist
\_ ...
\_ dockerfile
\_ package.json
\_ index.js
\_ ...
The docker-compose.yml includes the following
docker-compose.yml content
version: "3.4"
services:
app:
container_name: projectmanagerApp
restart: always
build:
context: ./app
dockerfile: ./app/dockerfile
dns:
- 1.1.1.1
- 1.0.0.1
ports:
- "80:8000"
depends_on:
- server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 30s
networks:
- projectmanagerNET
server:
container_name: projectmanagerServer
restart: always
image: node:10
build: ./server
dns:
- 1.1.1.1
- 1.0.0.1
ports:
- "81:8001"
expose:
- 8001
# links:
# - mongo
# depends_on:
# - mongo
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8001"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 30s
networks:
- projectmanagerNET
# mongo:
# container_name: projectmanagerMongo
# image: mongo
# dns:
# - 1.1.1.1
# - 1.0.0.1
# expose:
# - "27017"
# healthcheck:
# test: ["CMD", "echo", "'db.runCommand(\"ping\").ok'", "|", "mongo", "localhost:27017/test", "--quiet"]
# interval: 1m30s
# timeout: 10s
# retries: 3
# start_period: 30s
# networks:
# - projectmanagerNET
networks:
projectmanagerNET:
/app/dockerfile contents
### Initialisation
#Define the base image - using node v.10, official docker image
FROM node:10
#Define the maintainer of this image
LABEL maintainer="me@aljaxus.eu"
#Define the working directory (on final container)
WORKDIR /var/app
#Set the default registry for NPM
RUN npm config set registry http://registry.npmjs.org/
### Build process
# Copy the package.json, package-lock.json from host machine to build container
COPY package*.json ./
# Install all dependencies on the build container
RUN npm install --quiet
### Post build process
#Copy all the files from the build container to final container
COPY . .
#Start the server in the container
CMD [ "npm", "run", "serve" ]
Both subapps (app, server) can be build using docker build --rm --tag testingImage .
and run using docker run --name testContainer testingImage
and both startup without any errors at all.
But when using docker-compose I get the following errors:
Errors
Starting projectmanagerServer ... done
Starting projectmanagerApp ... done
Attaching to projectmanagerServer, projectmanagerApp
projectmanagerApp |
projectmanagerApp | > projectmanager-app@0.0.1 serve /var/app
projectmanagerApp | > node server.js
projectmanagerApp |
projectmanagerApp | internal/modules/cjs/loader.js:584
projectmanagerApp | throw err;
projectmanagerApp | ^
projectmanagerApp |
projectmanagerApp | Error: Cannot find module '/var/app/server.js'
projectmanagerApp | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
projectmanagerApp | at Function.Module._load (internal/modules/cjs/loader.js:508:25)
projectmanagerApp | at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
projectmanagerApp | at startup (internal/bootstrap/node.js:283:19)
projectmanagerApp | at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
projectmanagerApp | npm ERR! code ELIFECYCLE
projectmanagerApp | npm ERR! errno 1
projectmanagerApp | npm ERR! projectmanager-app@0.0.1 serve: `node server.js`
projectmanagerApp | npm ERR! Exit status 1
projectmanagerApp | npm ERR!
projectmanagerApp | npm ERR! Failed at the projectmanager-app@0.0.1 serve script.
projectmanagerApp | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
projectmanagerApp |
projectmanagerApp | npm ERR! A complete log of this run can be found in:
projectmanagerApp | npm ERR! /root/.npm/_logs/2019-03-11T19_23_58_394Z-debug.log
Short version: cmd node server.js
is executed for no reason at all, even though I have specified in the dockerfile the CMD [ "npm", "run", "serve" ]
Thank you for any support or suggestions what I might have done wrong in advance.