Dockerfile Overriding ENV variable

前端 未结 1 1920
孤城傲影
孤城傲影 2020-12-29 22:44

I have a Dockerfile and I\'d like to make the API configurable with a default value.

FROM socialengine/nginx-spa

ENV API_URL localhost:600

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 23:18

    What you have described should work just fine. Given:

    $ cat Dockerfile
    FROM socialengine/nginx-spa
    ENV API_URL localhost:6007
    $ docker build -t ui .
    [...]
    

    Consider this:

    $ docker run -it --rm ui env | grep API_URL
    API_URL=localhost:6007
    

    Compared to:

    $ docker run -it --rm -e API_URL='production:6007' ui env | grep API_URL
    API_URL=production:6007
    

    Passing a -e VARNAME=varvalue on the docker run command line will override a default set in your Dockerfile.

    If you are seeing different behavior, please update your question to show exactly the command you are running and the associated output.

    Update

    Here is the complete example, recorded for your viewing pleasure:

    https://asciinema.org/a/a5a2n3exlyh4jkii4k0ivvqmd

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