Home > OS >  Can I update node.js version in a dockerfile from another docker image?
Can I update node.js version in a dockerfile from another docker image?

Time:12-14

I would like to ask how to node.js version in a dockerfile from another docker image.

I'm using puppeteer's official image ghcr.io/puppeteer/puppeteer:latest which is using node.js 16.18.1. https://pptr.dev/guides/docker/

However, I want to use a package that is required to use node.js >= 18. Could I update it in my dockerfile?

My current dockerfile is very simple. I have no idea how to update it.

FROM ghcr.io/puppeteer/puppeteer:latest

WORKDIR /app

COPY package.json /app
COPY yarn.lock /app

RUN yarn install

COPY . /app

CMD ["yarn", "start"]

CodePudding user response:

You can build your own puppeteer docker image base on node v18.

That is one of benefit open-source and docker.

#1 Clone 'puppeteer'source

full source code into your laptop(Ubuntu or Windows)

https://github.com/puppeteer/puppeteer

git clone https://github.com/puppeteer/puppeteer.git

You can see those files on the root

$ ls -ls
total 668
  4 -rw-rw-r--   1 isb isb   1034 Dec 12 14:57 commitlint.config.js
  4 drwxrwxr-x   3 isb isb   4096 Dec 12 15:22 docker
  4 drwxrwxr-x   5 isb isb   4096 Dec 12 15:21 docs
  4 drwxrwxr-x   2 isb isb   4096 Dec 12 14:57 examples
 12 -rw-rw-r--   1 isb isb  11344 Dec 12 14:57 LICENSE
 24 drwxrwxr-x 450 isb isb  20480 Dec 12 15:21 node_modules
  4 -rw-rw-r--   1 isb isb   3908 Dec 12 14:57 package.json
568 -rw-rw-r--   1 isb isb 580968 Dec 12 15:21 package-lock.json
  4 drwxrwxr-x   6 isb isb   4096 Dec 12 14:57 packages
 12 -rw-rw-r--   1 isb isb   8447 Dec 12 14:57 README.md
  4 -rw-rw-r--   1 isb isb    582 Dec 12 14:57 release-please-config.json
  4 drwxrwxr-x   8 isb isb   4096 Dec 12 14:57 test
  4 drwxrwxr-x   2 isb isb   4096 Dec 12 14:57 test-d
  4 drwxrwxr-x   4 isb isb   4096 Dec 12 14:57 tools
  4 -rw-rw-r--   1 isb isb    864 Dec 12 14:57 tsconfig.base.json
  4 -rw-rw-r--   1 isb isb   2207 Dec 12 14:57 versions.js
  4 drwxrwxr-x   6 isb isb   4096 Dec 12 14:57 website

#2 Change the Dockerfile FROM node 16 to 18

Before

FROM node:16

After

FROM node:18

#3 Create two tgz files

From root directory of #1 repository.

./docker/pack.sh

It will creare two files on the Docker directory

puppeteer-core-latest.tgz
puppeteer-latest.tgz
$ ls -ls
total 540
  4 -rw-rw-r-- 1 isb isb   1344 Dec 12 15:34 Dockerfile
  4 -rwxrwxr-x 1 isb isb    394 Dec 12 14:57 pack.sh
456 -rw-rw-r-- 1 isb isb 466051 Dec 12 15:22 puppeteer-core-latest.tgz
 68 -rw-rw-r-- 1 isb isb  67823 Dec 12 15:22 puppeteer-latest.tgz
  4 -rw-rw-r-- 1 isb isb    893 Dec 12 14:57 README.md
  4 drwxrwxr-x 2 isb isb   4096 Dec 12 14:57 test

#4 Build your own pupeteer docker image

/puppeteer/docker$ docker build -t puppeteer-chrome-linux-node-v18 .

Check the new docker image

$ docker image ls
REPOSITORY                                             TAG       IMAGE ID       CREATED          SIZE
puppeteer-chrome-linux-node-v18                        latest    25df4f861b30   10 seconds ago   1.97GB
puppeteer-chrome-linux                                 latest    9ddf63fe89c4   21 minutes ago   1.89GB

You can check new image which version of node

$ docker image inspect puppeteer-chrome-linux-node-v18:latest

Result in terminal

            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=18.12.1",
                "YARN_VERSION=1.22.19"
            ],

If you show current official image, show this node version.

            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=16.18.1",
                "YARN_VERSION=1.22.19"
            ],

detail here

#5 Build your new scrapy docker image base on #4 new image

FROM puppeteer-chrome-linux-node-v18:latest

WORKDIR /app

COPY package.json /app
COPY yarn.lock /app

RUN yarn install

COPY . /app

CMD ["yarn", "start"]
  • Related