title: ASP.NET Core : Where to keep the connection string? In Docker Profile or appsettings.json?
body: <p>I have an ASP.NET Core application and I have kept the connection string in the <code>appsettings.json</code> file.</p>
  <p>Should I also add the connection string in the Docker Profile as an environment variable?</p>
  <p>This is my <code>appsettings.json</code>:</p>
  <pre><code>{
      &quot;PersistenceAccess&quot;: {
          &quot;ConnectionString&quot;: &quot;Server=localhost;Port=5432;Database=DemoDatabase;User Id=postgres;Password=postgres;&quot;
      }
  }
  </code></pre>
  <p>And this is the Docker Profile in the <code>LaunchSettings.json</code>:</p>
  <pre><code>{
    &quot;iisSettings&quot;: {
      &quot;windowsAuthentication&quot;: false,
      &quot;anonymousAuthentication&quot;: true,
      &quot;iisExpress&quot;: {
        &quot;applicationUrl&quot;: &quot;http://localhost:35847&quot;,
        &quot;sslPort&quot;: 0
      }
    },
    &quot;profiles&quot;: {
      &quot;IIS Express&quot;: {
        ..
        }
      },
      &quot;Docker&quot;: {
        &quot;commandName&quot;: &quot;Docker&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;launchUrl&quot;: &quot;{Scheme}://{ServiceHost}:{ServicePort}&quot;,
        &quot;environmentVariables&quot;: {
          &quot;PersistenceAccess__ConnectionString&quot;: &quot;Server=host.docker.internal;Port=5432;Database=DemoDatabase;User Id=postgres;Password=postgres;&quot;
        },
        &quot;DockerfileRunArguments&quot;: &quot;--add-host host.docker.internal:host-gateway&quot;,
        &quot;publishAllPorts&quot;: true,
        &quot;useSSL&quot;: false
      }
    }
  }
  </code></pre>
  <p>I also have a <code>Docker-Compose.yml</code> file:</p>
  <pre><code>version: '3.4'
  
  services:
    Demo.api:
      image: ${DOCKER_REGISTRY-}demoapi
      build:
        context: .
        dockerfile: Sources/Code/Demo.Api/Dockerfile
      environment:
        - ASPNETCORE_ENVIRONMENT=Development
        - PersistenceAccess__ConnectionString= Server=db;Port=5432;Database=DemoDatabase;User Id=postgres;Password=postgres;
      ports:
        - '8081:80'
      depends_on:
      - db
    db:
       image: postgres
       restart: always
       environment:
          - POSTGRES_USER=postgres
          - POSTGRES_PASSWORD=postgres
       logging:
          options:
            max-size: 10m
            max-file: &quot;3&quot;
       ports:
            - '5438:5432'
       volumes:
          - ./postgres-data:/var/lib/postgresql/data
         # copy the sql script to create tables
          - ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
          # copy the sql script to fill tables
          - ./sql/fill_tables.sql:/docker-entrypoint-initdb.d/fill_tables.sql
  </code></pre>