title: Connect .NET Core Web API to MySQL on different docker container
body: <p>I have 2 docker containers running on same virtual machine (Ubuntu server 18.04 on VMWare workstation 12 Player). The first one is MySql Container, which is running on port 3306 and the second one is asp.net core (v2.0) web api (port 5000 on vm and export outside through nginx with port 80 ). My VM api is 192.168.20.197</p>
  
  <p><a href="https://i.stack.imgur.com/oDaiu.png" rel="nofollow noreferrer">project architecture image</a></p>
  
  <p>My connection string on web api project is: <code>optionsBuilder.UseMySQL("server=localhost;port=3306;database=mydatabase;user=root;CharSet=utf8");</code></p>
  
  <p>My docker file content is</p>
  
  <pre><code>FROM microsoft/dotnet:sdk AS build-env
  WORKDIR /app
  
  
  COPY *.csproj ./
  RUN dotnet restore
  
  
  COPY . ./
  RUN dotnet publish -c Release -o out
  
  
  FROM microsoft/dotnet:aspnetcore-runtime
  WORKDIR /app
  COPY --from=build-env /app/out .
  ENTRYPOINT ["dotnet", "DemoMySql.dll"]
  </code></pre>
  
  <p>I have tried to make a HTTP request to the web api on VM but server response error(500) when i tried to interact with the database (the web api is still work normally when i make it return a sample string such as 192.168.20.197/api/values/samplestring). So How can i connect the web api to mysql on different container ?</p>
  
  <p>p/s: Sorry for my bad grammar</p>