Docker, one or more build-args where not consumed

前端 未结 2 1238
萌比男神i
萌比男神i 2020-12-13 12:59

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 AD         


        
相关标签:
2条回答
  • 2020-12-13 13:22

    if you want to run on Docker-Compose with Dockerfile ;

    Docker-compose.yml ;

    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 ;

    FROM alpine
    ARG SOME_ARG
    ENV SOME_ENV=$SOME_ARG
    

    docker commands ;

    docker-compose down    
    docker volume rm somecontainer_volume
    docker-compose build --no-cache
    docker-compose up -d
    
    0 讨论(0)
  • 2020-12-13 13:33

    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.

    0 讨论(0)
提交回复
热议问题