Dockerfile dummy questions

Hi: wish to build a docker image with openjdk, nodejs images. The version number for openjdk and nodejs will be dynamic user input from gitlab runner. What is the right way to write a Dockerfile below? (use Dockerfile to build an openjdk image first, then run image and install nodejs inside container, then build a new image from this container is not an option)

Q1: Assuming user inputs are JDK_VER (e.g. 11) & NODE_VER (e.g. 12)

  1. FROM openjdk:$JDK_VER
    FROM node:$NODE_VER

    Or
  2. FROM openjdk:$JDK_VER
    RUN curl -fsSL https://deb.nodesource.com/setup_$NODE_VER.x | sudo -E bash - &&
    sudo apt-get install -y nodejs

    Or
  3. FROM alpine
    apk …

Q2: If Dockerfile is written as FROM openjdk11, the built docker image seems always ~ 1GB Debian, if wish to be smaller one, Dockerfile is written as FROM alpine? The issue is that if base image is alpine, user asked openjdk and nodejs version numbers might not be available below:
FROM alpine
apk add --no-cache nodejs:12

What is wrong? thanks