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
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
....
...
docker build --build-arg NODE_VERSION=12 -t platform-ops .
platform-ops
image with docker-compose.ymlCreate a docker-compose.yml
version: '3'
services:
web:
image: platform-ops
.....
....
RUN with docker-compose up -d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With