serhii.net

In the middle of the desert you can say anything you want

UNLISTED

23 Nov 2023

Docker OPT, ARG, etc

  • ENV: Dockerfile reference | Docker Docs
    • sets an environment variable for all the Dockerfile instructions following it
  • ARG: Dockerfile reference | Docker Docs
    • sets a variable, same as above from the line where the instruction is
    • docker build --build-arg username=what_user .
  • Both ENV and ARG are usable in a RUN instruction; ARGs can be used for ENVs
  • Docker ARG, ENV and .env - a Complete Guide · vsupalov.com
    • ENV is available when actually RUNNING containers
    • ARG is available in the Dockerfile during the build process, and are not usable within running containers
    • ARG
      • has to be provided if specified, has to be specified if provided
      • can have a default value: ARG some_var=some_default_value
    • ENV
      • has to have a value if specified
##	a) allows setting the env. variable through `-e` when running
##	b) allows not-setting BUCKET_NAME, then $BUCKET_NAME will stay empty 
##	c) allows using $BUCKET_NAME in runtime (CMD)
##	d) allows setting `ARG BUCKET_NAME=some_default` value that 
##		stays if not overwritten with `-e`

ARG BUCKET_NAME
ENV BUCKET_NAME $BUCKET_NAME
CMD whatever $BUCKET_NAME

This that the program itself reads from environment can be ued as-isqj:w

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus