Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Docker, one or more build-args where not consumed

I'm trying to build Oracle WebLogic Docker image with custom environment variables

$ docker build -t 12213-domain --build-arg ADMIN_PORT=8888 --build-arg ADMIN_PASSWORD=wls .

but I get the following warning on the build log

[Warning] One or more build-args [ADMIN_PASSWORD ADMIN_PORT] were not consumed

Here is the Dockerfile of the image I'm trying to build

#Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.
#
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
# ORACLE DOCKERFILES PROJECT
# --------------------------
# This Dockerfile extends the Oracle WebLogic image by creating a sample domain.
#
# Util scripts are copied into the image enabling users to plug NodeManager 
# automatically into the AdminServer running on another container.
#
# HOW TO BUILD THIS IMAGE
# -----------------------
# Put all downloaded files in the same directory as this Dockerfile
# Run: 
#      $ sudo docker build -t 12213-domain
#
# Pull base image
# ---------------
FROM oracle/weblogic:12.2.1.3-developer

# Maintainer
# ----------
MAINTAINER Monica Riccelli <monica.riccelli@oracle.com>

# WLS Configuration 
# ---------------------------
ENV ADMIN_HOST="wlsadmin" 
    NM_PORT="5556" 
    MS_PORT="8001" 
    DEBUG_PORT="8453" 
    ORACLE_HOME=/u01/oracle 
    SCRIPT_FILE=/u01/oracle/createAndStartWLSDomain.sh 
    CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true"  
    PATH=$PATH:/u01/oracle/oracle_common/common/bin:/u01/oracle/wlserver/common/bin:/u01/oracle/user_projects/domains/${DOMAIN_NAME:-base_domain}/bin:/u01/oracle

# Domain and Server environment variables
# ------------------------------------------------------------
ENV DOMAIN_NAME="${DOMAIN_NAME:-base_domain}" 
    PRE_DOMAIN_HOME=/u01/oracle/user_projects 
    ADMIN_PORT="${ADMIN_PORT:-7001}"  
    ADMIN_USERNAME="${ADMIN_USERNAME:-weblogic}" 
    ADMIN_NAME="${ADMIN_NAME:-AdminServer}" 
    MS_NAME="${MS_NAME:-""}" 
    NM_NAME="${NM_NAME:-""}" 
    ADMIN_PASSWORD="${ADMIN_PASSWORD:-""}" 
    CLUSTER_NAME="${CLUSTER_NAME:-DockerCluster}" 
    DEBUG_FLAG=true 
    PRODUCTION_MODE=dev 

# Add files required to build this image
COPY container-scripts/* /u01/oracle/

#Create directory where domain will be written to
USER root
RUN chmod +xw /u01/oracle/*.sh &&  
    chmod +xw /u01/oracle/*.py &&  
    mkdir -p $PRE_DOMAIN_HOME &&  
    chmod a+xr $PRE_DOMAIN_HOME && 
    chown -R oracle:oracle $PRE_DOMAIN_HOME

VOLUME $PRE_DOMAIN_HOME
# Expose Node Manager default port, and also default for admin and managed server 
EXPOSE $NM_PORT $ADMIN_PORT $MS_PORT $DEBUG_PORT

USER oracle
WORKDIR $ORACLE_HOME

# Define default command to start bash. 
CMD ["/u01/oracle/createAndStartWLSDomain.sh"]

I'm running docker-toolbox on windows, and the docker version is

$ docker --version
Docker version 18.03.0-ce, build 0520e24302
question from:https://stackoverflow.com/questions/49651369/docker-one-or-more-build-args-where-not-consumed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ARG

ARG <name>[=<default value>]

The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg = flag. If a user specifies a build argument that was not defined in the Dockerfile, the build outputs a warning.

[Warning] One or more build-args [foo] were not consumed.

https://docs.docker.com/engine/reference/builder/#arg

Using ARG variables

You can use an ARG or an ENV instruction to specify variables that are available to the RUN instruction. Environment variables defined using the ENV instruction always override an ARG instruction of the same name. Consider this Dockerfile with an ENV and ARG instruction.

Unlike an ARG instruction, ENV values are always persisted in the built image. Consider a docker build without the --build-arg flag:

ARG is only available during the build of a Docker image (RUN etc), not after the image is created and containers are started from it (ENTRYPOINT, CMD). You can use ARG values to set ENV values to work around that.

So you need to do something like this

# Assign any default value to avoid any error. do not worry your build flag will override this.

    ARG ADMIN_PORT=some_default_value 

    ENV ADMIN_PORT=${ADMIN_PORT}

https://vsupalov.com/docker-arg-env-variable-guide/

Update:

In simple Word, If you pass ARGs like --build-arg SOME_ARG=some_value to Docker build and did not declare the ARGS in Dockerfile this warning will be printed.

my Dockerfile to consume ARG

FROM alpine
ARG SOME_ARG="Default_Value"
RUN echo "ARGS is ${SOME_ARG}"

Build command

docker build --no-cache --build-arg SOME_ARG=some_value -t alpine .

So it will not print any Warning as ARGS is declared in my Dockerfile.

Now if try to remove ARGS from Dockerfile and build the image

FROM alpine
RUN echo "without ARGS dockerfile"

Build command

docker build --no-cache --build-arg SOME_ARG=some_value -t alpine .

So now we will get a [Warning] One or more build-args [SOME_ARG] were not consumed because we did not consume or declared SOME_ARG in our Dockerfile.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...