Below is the Dockerfile located in the root directory of my express server:
FROM node:18
WORKDIR /usr/src/server
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
RUN npm run build
CMD ["npm", "start"]
Here is the contents of my .dockerignore file:
node_modules
dist
Dockerfile
Additionally, here is the content of my package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon src/server.ts",
"build": "tsc",
"start": "node dist/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/bcrypt": "^5.0.0",
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/jsonwebtoken": "^9.0.1",
"@types/node": "^18.15.11",
"@types/socket.io": "^3.0.2",
"nodemon": "^2.0.22",
"prisma": "^4.12.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"dependencies": {
"@prisma/client": "^4.12.0",
"bcrypt": "^5.1.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"socket.io": "^4.6.1"
}
}
Upon running the command
docker build --no-cache -t chat-server .
, the following output is displayed:
[+] Building 11.5s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 185B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 68B 0.0s
=> [internal] load metadata for docker.io/library/node:18 1.0s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [1/6] FROM docker.io/library/node:18@sha256:ee0a21d64211d 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 152.14kB 0.0s
=> CACHED [2/6] WORKDIR /usr/src/server 0.0s
=> [3/6] COPY package*.json ./ 0.0s
=> [4/6] RUN npm install 7.4s
=> [5/6] COPY . . 0.0s
=> ERROR [6/6] RUN npm run build 2.8s
------
> [6/6] RUN npm run build:
#11 0.509
#11 0.509 > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="77041205011205374659475947">[email protected]</a> build
#11 0.509 > tsc
#11 0.509
#11 2.763 src/controllers/conversationsController.ts(63,12): error TS7006: Parameter 'participant' implicitly has an 'any' type.
#11 2.763 src/controllers/conversationsController.ts(105,10): error TS7006: Parameter 'participant' implicitly has an 'any' type.
#11 2.763 src/controllers/conversationsController.ts(160,41): error TS7006: Parameter 'conversation' implicitly has an 'any' type.
#11 2.763 src/controllers/conversationsController.ts(170,12): error TS7006: Parameter 'participant' implicitly has an 'any' type.
#11 2.763 src/controllers/messagesController.ts(44,16): error TS7006: Parameter 'participant' implicitly has an 'any' type.
#11 2.763 src/controllers/messagesController.ts(45,19): error TS7006: Parameter 'participant' implicitly has an 'any' type.
The scenario described above raises concerns about the occurrence of these unexpected type errors during the execution of the command. Despite the successful outcome when executing npm run build
directly in the terminal, the inconsistency persists.
An attempt to resolve this issue was made by excluding the package-lock.json file in the Dockerfile.