It is not possible to have two base images at same time in a Dockerfile
However, it is possible to have different base images executed after one another. When the second image is loaded, the first image is automatically deleted
Consider the following usecase: We use a base image to build the code, and then use a different base image to deploy the code. This setting is commonly used in production of nodejs code
## First image
#builder is the ID of the current phase. This id will be used in next phase
FROM node:alpine as builder
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
RUN npm run build #creates folder /app/build
##Second image. No need to specify phase name here
FROM nginx #npm is no longer available
COPY --from=builder /app/build /usr/share/nginx/html #Copy files from previous phase
NOTE:
Although django or nodejs have their own development server, they are not used for production as they are slow. Hence we use services like nginx and gunicorn. Check here to see how to dockerize django on development and production environments