docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.56k stars 481 forks source link

args in build not passed to Dockerfile #2726

Closed Inconvenant closed 1 month ago

Inconvenant commented 1 month ago

hello, args in build in compose are not passed to Dockerfile

it was working in 20.10.14 not working in 27.3.1 I'm getting this warning and no values : WARN: InvalidDefaultArgInFrom: Default value for ARG ${NODERED_IMAGE}:${NODERED_VERSION} results in empty or invalid base image name (line 5) I should have get values from the .env

Regards docker-compose.txt Dockerfile.txt env.txt

thaJeztah commented 1 month ago

I think this is only a warning; the warning is that the Dockerfile is not following best practices; the recommendation is for these args to have a sensible default in the Dockerfile itself, so that building the Dockerfile without passing build-args to override the defaults will still work.

See; https://docs.docker.com/reference/build-checks/invalid-default-arg-in-from/

In your case, the Dockerfile could look like;

# syntax=docker/dockerfile:1

# defaults (can be overridden)
ARG NODERED_IMAGE=nodered/node-red
ARG NODERED_VERSION=4.0

FROM ${NODERED_IMAGE}:${NODERED_VERSION} 

RUN npm install --save node-red-contrib-dockerode node-red-contrib-postgresql

COPY ./settings.js /data/settings.js

USER root
RUN chown -R node-red:root /data

USER node-red

This would set defaults in the dockerfile itself, but those can be overridden at build-time.

thaJeztah commented 1 month ago

Let me also move this to the buildx repository, as this is more related to buildkit / buildx

Inconvenant commented 1 month ago

I think this is only a warning; the warning is that the Dockerfile is not following best practices; the recommendation is for these args to have a sensible default in the Dockerfile itself, so that building the Dockerfile without passing build-args to override the defaults will still work.

See; https://docs.docker.com/reference/build-checks/invalid-default-arg-in-from/

In your case, the Dockerfile could look like;

syntax=docker/dockerfile:1

defaults (can be overridden)

ARG NODERED_IMAGE=nodered/node-red ARG NODERED_VERSION=4.0

FROM ${NODERED_IMAGE}:${NODERED_VERSION}

RUN npm install --save node-red-contrib-dockerode node-red-contrib-postgresql

COPY ./settings.js /data/settings.js

USER root RUN chown -R node-red:root /data

USER node-red This would set defaults in the dockerfile itself, but those can be overridden at build-time.

thanks, I understand the warning and indeed I don't get any warning if I put default values I was using this guide : https://vsupalov.com/docker-arg-env-variable-guide/ and was in the wrong believing my RUN echo of my ARG would display in my standard output while building