Welcome to the Linux Foundation Forum!

Problems and Fixes for LFS261 - LAB 7

Working on Lab 7 I found a number of inconsistencies that if you follow the lab you won't be able to run nor build your docker images. First the Javascript code isn't compatible with the node docker image version that you're told in the lab node:18-slim you need to use node:8.9.0-slim. After you've changed the version of node, these command will finaly work :

npm install -this will install modules from package.json
npm audit fix -this will fix known vulnerabilities in the modules
installed by npm
npm ls - lists all modules downloaded by npm
npm test - runs unit tests to verify your code is ok
npm start

In the next step you're instructed to create a Dockerfile inside the result/ using the following:

FROM node:18-slim

RUN apt-get update && \
    apt-get install -y --no-install-recommends curl tini && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/app

RUN npm install -g nodemon

COPY package*.json ./

RUN     npm ci && \
    npm cache clean --force && \
    mv /usr/local/app/node_modules /node_modules

COPY . .

ENV PORT 80

EXPOSE 80

ENTRYPOINT ["/usr/bin/tini", "--"]

CMD ["node", "server.js"]

This Dockerfile has a number of additional problems:

  1. We already know that node 18 won't work, so we need to use node 8.9.0
  2. the docker image node:8.9.0-slim is based on an old Debian version (Debian 8.11"Jessie") that is no longer supported, so you can't run apt-get update nor install curl or tini.
  3. To fix this issue I had to build my own docker image using a more recent Debian version (Debian 11 "Bullseye") and install node 8.9.0 in it
  4. the command npm ci isn't a command for npm 5.5.1 (that's the version of npm that comes with node 8.9.0). So you have to replace it with npm install

At the end my new modified Dockerfile for results/ is:

FROM <my custom docker image>

RUN apt update && \ 
    apt-get install -y --no-install-recommends curl tini nano  && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/app 

RUN npm install nodemon -g

COPY package.json ./ 

RUN npm install && \
    npm cache clean --force && \
    mv /usr/local/app/node_modules /node_modules

COPY . .

ENV PORT 80
EXPOSE 80

ENTRYPOINT ["/usr/bin/tini", "--"]
CMD [ "node", "server.js" ]

Comments

Categories

Upcoming Training