Pass argument to docker compose

前端 未结 4 1380
失恋的感觉
失恋的感觉 2020-12-08 01:36

In my docker compose file there is a dynamic field which I\'d like to generate during the running. Actually it is a string template:

environment:
    - SERVE         


        
相关标签:
4条回答
  • 2020-12-08 02:13

    This is possible to with stack deploy

    Example Compose File in your environment section:

    - MY_VARIABLE_NAME=${MY_VARIABLE_VALUE}
    

    Stack Deploy Command (I ran this from Gitbash in Windows):

    MY_VARIABLE_VALUE=some-value docker stack deploy --compose-file compose_file_here stackname
    


    Reference See this Github post here

    0 讨论(0)
  • 2020-12-08 02:16

    In docker-compose, arguments are available and usefull only in dockerfile. You can specify what you are doing in the level ahead like following:

    #dockerfile
    ARG PORT
    ENV SERVER_URL "https://0.0.0.0:$PORT"
    

    Your port can be set in your docker-compose.yml:

    build:
      context: .
      args:
        - PORT=443
    

    It is actually an environment variable in any case. You can pass it through your run command if that fits to you:

    PORT=443 docker-compose run <service>
    #or
    docker-compose run <service> -e PORT=443
    
    0 讨论(0)
  • 2020-12-08 02:19

    You can use the flag when using docker-compose build

    docker-compose build --build-arg PRODUCTION=VALUE
    

    In Dockerfile you can get the argument PRODUCTION

    # Dockerfile
    ARG PRODUCTION
    FROM node:latest
    
    0 讨论(0)
  • 2020-12-08 02:39

    See this answer. You can do it like this: PORT=433 docker-compose <command>

    You can even provide multiple values: PORT=433 MYIP='192.168.123.456' docker-compose <command>

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