Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use user-secrets or environment variables with docker

When using docker with asp.net core for development, should I use user-secrets or environment variables? I am using the default docker file that Visual Studio 2017 creates when adding a project, which uses microsoft/aspnetcore:1.1 and I believe is a linux image.

How do I set the user-secrets/environment variables in docker so they are set when it launches, but aren't included in the source code?

like image 391
darick_c Avatar asked Mar 11 '17 00:03

darick_c


2 Answers

For Development I rely on .net secret manager tool:

  1. use dotnet user-secrets to store secrets on the local computer
dotnet user-secrets init

dotnet user-secrets set "Movies:ServiceApiKey" "12345"
..

See MS docs: Safe storage of app secrets in development in ASP.NET Core.

  1. mount the local folder with secrets to Docker container

Example for Docker:

docker run ^
  -e ASPNETCORE_ENVIRONMENT=Development ^
  -v %APPDATA%/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro  ^
  company/image:latest

Example for docker-compose:

version: "3.8"

..

  net_core_service:
    ..
    environment:
      # should be defined Development-env to allow loading user-secrets located on the local computer.
      - ASPNETCORE_ENVIRONMENT=Development
    ..
    volumes:
      # map the dotnet user-secret folder
      - $APPDATA/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
    ..

..
like image 180
vladimir Avatar answered Oct 13 '22 00:10

vladimir


Environment vars are better - https://12factor.net/config

If you run docker using docker run use -e or --env-file option: https://docs.docker.com/engine/reference/run/#env-environment-variables

If you run docker using docker-compose use environment or env_file key: https://docs.docker.com/compose/environment-variables/

like image 29
luchaninov Avatar answered Oct 13 '22 01:10

luchaninov