2
  1. How to using env variables in Dockerfile?
  2. not args

This is my Dockerfile now:

FROM node:12

I want Dockerfile:

FROM node:$version

How can I do it? If it is not possible, then I will create a feature request for Docker.

halfer
  • 19,471
  • 17
  • 87
  • 173
  • 2
    That's exactly what `ARG` is designed for. There is no way to transparently get an environment variable from the host; you must explicitly pass it as a build argument. [Get environment variable value in Dockerfile](https://stackoverflow.com/questions/19537645/get-environment-variable-value-in-dockerfile) says more. – David Maze Aug 10 '20 at 23:17
  • @DavidMaze but I have a prod.env file, how can I pass all the variables from it to all stages of the Dockerfile build? help please = ( – Алексей Соснин Aug 10 '20 at 23:20
  • Usually you'd use an option like `docker run --env-file` to specify those settings at deploy time, and build your image against a fixed set of software. Ideally you run the exact same image in dev, QA, and production (and you wouldn't change the base version of Node between environments). – David Maze Aug 10 '20 at 23:59
  • @DavidMaze no, this is NOT runetimу variables, is variables like graphql endporint, rate limit, e.t.c. FOR WEBPACK. webpack is a ON OF multi part of stages build. This it NOT runtime variable =( its compile html files and script with ENV VALUES. its not runtime =( – Алексей Соснин Aug 11 '20 at 00:40

0 Answers0