How to set environment variables in Dockerfile via Azure DevOps

后端 未结 4 1624
栀梦
栀梦 2021-01-19 21:45

In my projects Docker file I have some environment variables, like this:

ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Password
ENV MSSQL_PID=Developer
ENV MSSQL_TCP_POR         


        
相关标签:
4条回答
  • 2021-01-19 22:25

    In release, choose deploy azure app service task. Provide required properties at App settings section under Application and Configuration Settings option.

    0 讨论(0)
  • 2021-01-19 22:34

    You can set an ARG var_name and reference ENV to the ARG variables. Then you can replace those variables when docker build the image $ docker build --build-arg var_name=$(VARIABLE_NAME)

    For example the add ARG in dockerfile, and have the ENV variable refer to it:

    ARG SECRET
    ENV ACCEPT_EULA=Y
    ENV SA_PASSWORD=$SECRET
    ENV MSSQL_PID=Developer
    ENV MSSQL_TCP_PORT=1433 
    

    You can use dock build task and dock push task separately, as buildandpush command cannot accept arguments. And set a variable SECRET in your pipeline.

    The set the Build Arguments SECRET= $(SECRET) to replace the ARG SECRET

    You can also refer to a similar thread.

    0 讨论(0)
  • 2021-01-19 22:36

    I am using the Replace Tokens extension for exactly tasks like this: https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens

    However, putting secrets into your Dockerfile might not be the best idea. Usually you would provide secrets or generally runtime configuration as environment variables when you actually execute the container.

    0 讨论(0)
  • 2021-01-19 22:38

    I suggest to set the environment variables at runtime. If you are deploying to an Azure App Service, app settings are injected into the process as environment variables automatically.

    You can then use the same image for multiple environments. With the Deploy Azure App Service task in a release pipeline, you can change the app settings for each environment.

    https://docs.microsoft.com/en-us/azure/app-service/configure-custom-container?pivots=container-linux#configure-environment-variables

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