Pass argument to docker compose

前端 未结 4 1428
失恋的感觉
失恋的感觉 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: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 
    #or
    docker-compose run  -e PORT=443
    

提交回复
热议问题