首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Docker,一个或多个未使用的build-args

Docker,一个或多个未使用的build-args
EN

Stack Overflow用户
提问于 2018-04-04 20:44:22
回答 2查看 41.7K关注 0票数 47

我正在尝试使用自定义环境变量构建Oracle WebLogic Docker镜像

代码语言:javascript
复制
$ docker build -t 12213-domain --build-arg ADMIN_PORT=8888 --build-arg ADMIN_PASSWORD=wls .

但是我在构建日志中得到了以下警告

代码语言:javascript
复制
[Warning] One or more build-args [ADMIN_PASSWORD ADMIN_PORT] were not consumed

下面是我正在尝试构建的镜像的Dockerfile

代码语言:javascript
复制
#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"]

我在windows上运行docker-toolbox,docker版本是

代码语言:javascript
复制
$ docker --version
Docker version 18.03.0-ce, build 0520e24302
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-05 00:21:23

参数

代码语言:javascript
复制
ARG <name>[=<default value>]

构建ARG指令定义了一个变量,用户可以在构建时通过docker build命令使用--

-arg=标志将该变量传递给构建器。如果用户指定了Dockerfile中未定义的构建参数,则构建将输出警告。

代码语言:javascript
复制
[Warning] One or more build-args [foo] were not consumed.

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

使用ARG变量的

您可以使用ARG或ENV指令来指定RUN指令可用的变量。使用ENV指令定义的环境变量始终覆盖同名的ARG指令。考虑这个带有ENV和ARG指令的Dockerfile。

与ARG指令不同,ENV值始终保存在构建的映像中。考虑一个没有-- build -arg标志的docker构建:

Docker ARG仅在镜像构建期间可用(运行等),而不是在镜像创建并从中启动容器之后(入口点,CMD)。你可以使用ARG值来设置ENV值来解决这个问题。

所以你需要这样做

代码语言:javascript
复制
# 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/

更新:

简而言之,如果您将像--build-arg SOME_ARG=some_value这样的参数传递给Docker build,并且没有在Dockerfile中声明这些参数,则将打印此警告。

我要使用ARG的Dockerfile

代码语言:javascript
复制
FROM alpine
ARG SOME_ARG="Default_Value"
RUN echo "ARGS is ${SOME_ARG}"

Build命令

代码语言:javascript
复制
docker build --no-cache --build-arg SOME_ARG=some_value -t alpine .

因此,它不会输出任何警告,因为在我的Dockerfile文件中声明了ARGS。

现在,如果尝试从Dockerfile中删除参数并构建映像

代码语言:javascript
复制
FROM alpine
RUN echo "without ARGS dockerfile"

Build命令

代码语言:javascript
复制
docker build --no-cache --build-arg SOME_ARG=some_value -t alpine .

因此,现在我们将得到一个警告,一个或多个构建参数SOME_ARG未使用,因为我们没有在Dockerfile中使用或声明SOME_ARG。

票数 78
EN

Stack Overflow用户

发布于 2020-05-20 02:41:35

如果你想在Docker上运行--用Dockerfile编写;

Docker-compose.yml;

代码语言:javascript
复制
version: '3.3'
services:
  somecontb:
    container_name: somecontainer
    hostname : somecontainer
    build:
      args:
        SOME_ARG: Default_Value
    context: .
      dockerfile: DockerFile
        image : someimage
    volumes:
      - somecontainer_volume:/somefile
volumes:
    somecontainer_volume:
.
.
.

DockerFile;

代码语言:javascript
复制
FROM alpine
ARG SOME_ARG
ENV SOME_ENV=$SOME_ARG

docker命令;

代码语言:javascript
复制
docker-compose down    
docker volume rm somecontainer_volume
docker-compose build --no-cache
docker-compose up -d
票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49651369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档