Question about ARGs/Envs in dockerfile suggested in T3 website.
I am not a docker veteran however on this page the example seems a bit wrong.
so on this block
ARG DATABASE_URL is not gonna be used on the build step isn't it? and it is not provided also with the build command. so it might be not needed here?
and the next line
ARG NEXT_PUBLIC_CLIENTVAR gets the ARG but never actually puts it into ENV so the build can have it. shoudn't we add a line here like:
ENV NEXT_PUBLIC_CLIENTVAR=$NEXT_PUBLIC_CLIENTVAR
?
Would be nice if someone with more experience with Docker can take a look at this and let me know if my suspissions are right?
3 Replies
@amir The example is correct. Arguments are available to run commands as environment variables but only during image build. Once container is started there is no such variable (that is why they have separate example with
DATABASE_URL
env passed during docker run
Take look at this snippet:
It produces this log during build:
It all depends on whether the app has those values baked in and next does this a lot. Unfortunately, because changing some of those values at runtime becomes much harder depending on where they are used.@Rivenris thanks for the info. did not know that ARGs are available as env vars in build time 🙂
so if i understood it right, the
DATABASE_URL
is also defined in build time even though it should technically be only run time var since next
might use it somehow in the build?Next will use this to get data on static pages
So if you have any static pages (including
notFound
) that might have data dependency on it, then next will connect to the db to use it