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 :

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

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

  1. FROM node:18-slim
  2.  
  3. RUN apt-get update && \
  4. apt-get install -y --no-install-recommends curl tini && \
  5. rm -rf /var/lib/apt/lists/*
  6.  
  7. WORKDIR /usr/local/app
  8.  
  9. RUN npm install -g nodemon
  10.  
  11. COPY package*.json ./
  12.  
  13. RUN npm ci && \
  14. npm cache clean --force && \
  15. mv /usr/local/app/node_modules /node_modules
  16.  
  17. COPY . .
  18.  
  19. ENV PORT 80
  20.  
  21. EXPOSE 80
  22.  
  23. ENTRYPOINT ["/usr/bin/tini", "--"]
  24.  
  25. 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:

  1. FROM <my custom docker image>
  2.  
  3. RUN apt update && \
  4. apt-get install -y --no-install-recommends curl tini nano && \
  5. rm -rf /var/lib/apt/lists/*
  6.  
  7. WORKDIR /usr/local/app
  8.  
  9. RUN npm install nodemon -g
  10.  
  11. COPY package.json ./
  12.  
  13. RUN npm install && \
  14. npm cache clean --force && \
  15. mv /usr/local/app/node_modules /node_modules
  16.  
  17. COPY . .
  18.  
  19. ENV PORT 80
  20. EXPOSE 80
  21.  
  22. ENTRYPOINT ["/usr/bin/tini", "--"]
  23. CMD [ "node", "server.js" ]

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training