Environment Variables

Hello. I am dusting down a toolkit which a developed some time ago. I originally develped it on Linux Mint (~20).
I am now on:

  • Linux Mint 21.3.
  • version 27.3.1, build ce12230

This used to work fine, and other than what is likely to be a later version of docker, I’m not sure worl be the cause.

I am now finding that I get warnings from the docker build command, referencing a shell variable, which is included to my Dockerfile. Whilst trying to work out what’s gone wrong, I notice that you are supposed to declare these in the Dockerfile and pass as a command line argument, although I didn’t need to do this originally.

So my Dockerfile looks like this:

  1 # Author: Clive Bostock
  2 #   Date: 22 Aug 2021
  3 #
  4 # Docker file to automate the setup of a database and automatic install
  5 # of APEX.
  6 #
  7 # Relies on scripting in the deploy folder and the contents of the 
  8 # inventory folder. This must include the ORDS R21 xip file and 
  9 # chosen versions of APEX from 19.x onwards (18 has not been tested, but 
 10 # may work).
 11 #
 12 # This has been tested with APEX 19.2 and 21.1.
 13 #
 14 # Base our image on the Oracle enterprise database container.
 15 ARG DAPEX_HOME
 16 ARG ORACLE_HOME
 17 ARG ORACLE_BASE
 18 
 19 FROM container-registry.oracle.com/database/enterprise:latest
 20 
 21 # Expose any ports we may need. We'll probably reduce the list.
 22 EXPOSE 1521
 23 EXPOSE 8080
 24 
 25 # We need root access to install packages
 26 USER root
 27 
 28 # Install vi in case we wish to edit any files inside the container.
 29 RUN yum -y install vi && yum -y clean all  && rm -rf /var/cache
 30 
 31 # Install java, since we need it for ORDS.
 32 RUN yum -y install java && yum -y clean all  && rm -rf /var/cache
 33 
 34 # Switch back to Oracle.
 35 USER oracle
 36 
 37 # We want the files to be owned by Oracle (uid 54321)
 38 COPY --chown=54321 ${DAPEX_HOME}/deploy/setup   $ORACLE_BASE/scripts/setup/
 39 COPY --chown=54321 ${DAPEX_HOME}/deploy/startup $ORACLE_BASE/scripts/startup/
 40 COPY --chown=54321 ${DAPEX_HOME}/inventory/apex $ORACLE_BASE/scripts/setup/
 41 RUN mkdir -p /var/tmp/dapex/log
 42 RUN mkdir -p /home/oracle/sqlcl
 43 COPY --chown=54321 ${DAPEX_HOME}/deploy/bin /var/tmp/dapex/bin
 44 COPY --chown=54321 ${DAPEX_HOME}/inventory/schemas /var/tmp/dapex/schemas
 45 

(I have left the line numbers in from the editor for convenience)
When I try to build, I get the warnings:

clive@ryzen-mint:~/dapex$ docker build --build-arg DAPEX_HOME=/home/clive/dapex  -t dapex19c .
[+] Building 3.7s (6/14)                                                                                 docker:default
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 1.53kB                                                                             0.0s
 => WARN: UndefinedVar: Usage of undefined variable '$DAPEX_HOME' (line 38)                                        0.0s
 => WARN: UndefinedVar: Usage of undefined variable '$DAPEX_HOME' (line 39)                                        0.0s
 => WARN: UndefinedVar: Usage of undefined variable '$DAPEX_HOME' (line 40)                                        0.0s
 => WARN: UndefinedVar: Usage of undefined variable '$DAPEX_HOME' (line 43)                                        0.0s
 => WARN: UndefinedVar: Usage of undefined variable '$DAPEX_HOME' (line 44)                                        0.0s
 => [internal] load metadata for container-registry.oracle.com/database/enterprise:latest                          0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 4.49kB                                                                                0.0s
 => CACHED [ 1/10] FROM container-registry.oracle.com/database/enterprise:latest                                   0.0s
 => CANCELED [ 2/10] RUN yum -y install vi && yum -y clean all  && rm -rf /var/cache                               3.7s

I am struggling to work out what is going on. Any help appreciated.

Thanks,

Clive

A. These are build arguments, not environment variables

B. Build args are only used by stages they’re declared in, so you need to redeclare the ARG lines after your FROM line

Thanks - that seems to have sorted that problem!