title: System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString') asp.net Core Docker-compose
body: <p>I have a dockerized asp.net Core application trying to connect to a mySql Database. Both are running inside a docker-compose. When I test the connection to a local Database without Docker, my code is working fine, but when I deploy it on a Vm inside docker-compose and that I call one of my controller, I get this error : <em>System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')</em> .
  Here is my docker-compose :</p>
  
  <pre><code>version: '3'
  services:
    dbgil:
     container_name: dbgil
     image: mysql
     restart: always
     ports:
       - 3306:3306
     environment:
       MYSQL_ROOT_PASSWORD: root
     volumes:
       - dbdata:/var/lib/mysql
    webserver:
      depends_on:
        - dbgil
      image: lionelquirynen/gillesquirynensys:latest
      ports:
        - "8021:80"
      links:
        - dbgil
  volumes:
      dbdata:
  </code></pre>
  
  <p>And here is my startup in my asp.net core application : </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using GillesQuirynenSys.Data;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore.Infrastructure;
  using Microsoft.EntityFrameworkCore.Storage;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  using Microsoft.Extensions.Logging;
  
  namespace GillesQuirynenSys
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllers();
              services.AddDbContext&lt;MySqlDbContext&gt;(options =&gt;
                  options.UseMySql("server=localhost;port=3306;database=test;user=root;password=root;convert zero datetime=True"));
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MySqlDbContext context)
          {
              context.Database.EnsureCreated();
              var databaseCreator = context.GetService&lt;IRelationalDatabaseCreator&gt;();
              databaseCreator.CreateTables();
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              app.UseHttpsRedirection();
  
              app.UseRouting();
  
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  }
  
  
  </code></pre>
  
  <p>I first had my connection string in my appsettings.json but I was getting the same error so I tried to hardcode it but it did not change anything. Has anyone any ideas? It seems like my configuration is working fine (at least, it is locally without Docker).</p>
  
  <p>PS: Here is the DockerFile of my asp.net Core application before pushing it to DockerHub :</p>
  
  <pre><code>#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
  
  FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
  WORKDIR /app
  EXPOSE 80
  
  FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
  WORKDIR /src
  COPY ["GillesQuirynenSys/GillesQuirynenSys.csproj", "GillesQuirynenSys/"]
  RUN dotnet restore "GillesQuirynenSys/GillesQuirynenSys.csproj"
  COPY . .
  WORKDIR "/src/GillesQuirynenSys"
  RUN dotnet build "GillesQuirynenSys.csproj" -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish "GillesQuirynenSys.csproj" -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT ["dotnet", "GillesQuirynenSys.dll"]
  </code></pre>