How to set an environment variable in a running docker container

前端 未结 11 1157
难免孤独
难免孤独 2020-11-29 23:28

If I have a docker container that I started a while back, what is the best way to set an environment variable in that running container? I set an environment variable initia

11条回答
  •  时光取名叫无心
    2020-11-30 00:13

    There are generaly two options, because docker doesn't support this feature now:

    1. Create your own script, which will act like runner for your command. For example:

      #!/bin/bash
      export VAR1=VAL1
      export VAR2=VAL2
      your_cmd
      
    2. Run your command following way:

      docker exec -i CONTAINER_ID /bin/bash -c "export VAR1=VAL1 && export VAR2=VAL2 && your_cmd"
      

提交回复
热议问题