Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker. How to pass arguments to FROM clause?

I have a Dockerfile with such contents:

# myimage
ARG NODE_VERSION=10
FROM node:${NODE_VERSION}
...

I want user can specify that argument in its own Dockerfile/docker-compose.yml like that

# user_image
ARG NODE_VERSION=12
FROM myimage
...

It seems like that approach is not working

like image 474
IC_ Avatar asked Oct 19 '25 01:10

IC_


1 Answers

Setting the Default Docker Environment Variables During Image Build is possible using ARG to pass through --build-arg flag with variable and its values right into ENV.

The best practice is to create image and run the container isolated as follows.

Create a Dockerfile

ARG NODE_VERSION=default_value
FROM node:${NODE_VERSION}
.....
.....
ENV NODE_VERSION=$NODE_VERSION
....
...
  • Build the image with docker build --build-arg NODE_VERSION=12 -t platform-ops .
  • Run the platform-ops image with docker-compose.yml

Create a docker-compose.yml

version: '3'
services:
  web:
    image: platform-ops
    .....
    ....

RUN with docker-compose up -d

like image 115
Jinna Balu Avatar answered Oct 21 '25 14:10

Jinna Balu