title: Docker-Compose YML with ASP.NET Core 2.2 Web API and SQL Server 2017
body: <p>I am new to Docker (v19.03.0) which I am using with Visual Studio 2019 (v16.2.0) and .NET Core 2.2, and I was hoping I could get some help with my <code>docker-compose.yml</code> file as want to create a microservice that consists of my Web API and SQL Server 2017.</p>
  
  <p>At the moment, my Web API is pointing to a containerised Linux instance of SQL 2017, which is volume mounting my database from my <code>C:\DockerVolumes</code> drive.  This is working via IIS perfectly fine at the moment.  </p>
  
  <p>The next step was to containerise my Web Api which I did by right clicking my project in Visual Studio, and after running <code>docker ps -a</code> it seems to be running along side my SQL container.</p>
  
  <p>Here is my <code>docker-compose.yml</code></p>
  
  <pre><code>version: '3.7'
  services:
      web:
          build:
              dockerfile: Dockerfile
              context: .
          ports:
              - '8080:80'
          depends_on:
              - db
      db:
          image: 'mcr.microsoft.com/mssql/server:2017-latest'
          ports:
              - '1433:1433'
          volumes:
              - 'C:\DockerVolumes:/var/opt/mssql/data'
          environment:
              SA_PASSWORD: 12345678
              ACCEPT_EULA: Y
  </code></pre>
  
  <p>This is where my <code>docker-compose.yml</code> and <code>Dockerfile</code> for my Web API reside:</p>
  
  <p><a href="https://i.stack.imgur.com/dPj5Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPj5Y.png" alt="File Explorer Visual Studio"></a></p>
  
  <p>Here is the <code>Dockerfile</code> for my Web Api:</p>
  
  <pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
  WORKDIR /app
  EXPOSE 80
  
  FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
  WORKDIR /src
  COPY ["SnowdonAPI_05/SnowdonAPI_05.csproj", "SnowdonAPI_05/"]
  RUN dotnet restore "SnowdonAPI_05/SnowdonAPI_05.csproj"
  COPY . .
  WORKDIR "/src/SnowdonAPI_05"
  RUN dotnet build "SnowdonAPI_05.csproj" -c Release -o /app
  
  FROM build AS publish
  RUN dotnet publish "SnowdonAPI_05.csproj" -c Release -o /app
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  ENTRYPOINT ["dotnet", "SnowdonAPI_05.dll"]
  </code></pre>
  
  <p>Before I do anything else I wanted to make sure I haven't missed anything (either steps or things in my <code>yml</code> file, obviously the only thing I can think of with regards to my Web Api is changing the connection string to <code>server=db;.....</code> once the services start.  Also, I am not sure if the port mapping are necessary for SQL?</p>
  
  <p>Any help would be much appreciated, and if there is anymore information needed let me know.</p>