我正在尝试使用自定义环境变量构建Oracle WebLogic Docker镜像
$ docker build -t 12213-domain --build-arg ADMIN_PORT=8888 --build-arg ADMIN_PASSWORD=wls .
Run Code Online (Sandbox Code Playgroud)
但是我在构建日志中收到以下警告
[Warning] One or more build-args [ADMIN_PASSWORD ADMIN_PORT] were not consumed
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试构建的映像的Dockerfile
#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"]
Run Code Online (Sandbox Code Playgroud)
我正在Windows上运行docker-toolbox,而docker版本则是
$ docker --version
Docker version 18.03.0-ce, build 0520e24302
Run Code Online (Sandbox Code Playgroud)
Adi*_*iii 26
ARG
ARG <name>[=<default value>]
Run Code Online (Sandbox Code Playgroud)
ARG指令使用--build-arg = flag定义一个变量,用户可以使用docker build命令在构建时将该变量传递给构建器.如果用户指定了未在Dockerfile中定义的构建参数,则构建会输出警告.
[Warning] One or more build-args [foo] were not consumed.
Run Code Online (Sandbox Code Playgroud)
https://docs.docker.com/engine/reference/builder/#arg
使用ARG变量
您可以使用ARG或ENV指令指定RUN指令可用的变量.使用ENV指令定义的环境变量始终覆盖同名的ARG指令.考虑这个带有ENV和ARG指令的Dockerfile.
与ARG指令不同,ENV值始终保留在构建的图像中.考虑没有--build-arg标志的docker构建:
ARG仅在构建Docker镜像(RUN等)时可用,而不是在创建图像并从中启动容器(ENTRYPOINT,CMD)之后.您可以使用ARG值来设置ENV值以解决此问题.
所以你需要做这样的事情
# 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}
Run Code Online (Sandbox Code Playgroud)
https://vsupalov.com/docker-arg-env-variable-guide/
归档时间: |
|
查看次数: |
15732 次 |
最近记录: |