Docker Community Forums

Share and learn in the Docker community.

Docker Compose with .NET Core & SQL Server

i’m trying to compose the .net core 5.0 and Sql server. i’m getting the below error

Attaching to webapisqlserver_code_1, webapisqlserver_api_1
api_1 | Could not execute because the specified command or file was not found.
api_1 | Possible reasons for this include:
api_1 |
**** You misspelled a built-in dotnet command.***
api_1 | * You intended to execute a .NET program, but dotnet-WebApiSQLServer.dll does not exist.
api_1 | * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
**
**

here is my docker compose file
version: ‘3.8’

services: 

    code:

        image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu

        environment: 

            ACCEPT_EULA: "Y"

            SA_PASSWORD: "Password2020"

            MSSQL_PID: Express

        ports: 

            - "1433:1433"

    api:

        build: .

        depends_on: 

            - code

        environment: 

            ServerName: "ms-sql-demo"

            Database: "WebAPISQLServer"

            UserName: "SA"

            Password: "Password2020"

        ports: 

            - "8080:80"

docker file

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 

WORKDIR /app

# Copy csproj and restore as distinct layers

COPY *.csproj ./

RUN dotnet restore

# Copy everything else and build

COPY . ./

RUN dotnet publish -c Release -o out

# Build runtime image

FROM mcr.microsoft.com/dotnet/sdk:5.0

WORKDIR /app

EXPOSE 80

COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "WebApiSQLServer.dll"]

Configuring SQL Server on Docker
If you open your docker-compose.yml file, it should currently look something like this:

version: ‘3.4’

services:
dockersqlserver:
image: ${DOCKER_REGISTRY-}dockersqlserver
build:
context: .
dockerfile: DockerSqlServer/Dockerfile

COPY
This is the Docker Compose configuration for the ASP.NET Core app. To add a SQL Server container, modify the YAML file to look like this:

version: ‘3.4’

services:
db:
image: “mcr.microsoft.com/mssql/server:2017-latest
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=1Secure*Password1

dockersqlserver:
image: ${DOCKER_REGISTRY-}dockersqlserver
build:
context: .
dockerfile: DockerSqlServer/Dockerfile
depends_on:
- db

COPY
Here we have added a new container called db which uses the official SQL Server Docker image. The main property you need to be concerned about is SA_PASSWORD, which you should change to your own secure password.

PLEASE NOTE: The SA_PASSWORD field seems to have some strict criteria on what the password needs to contain. I couldn’t find the exact requirements, but it would be advisible to use a long password using upper and lowercase characters, numbers and special characters. For the purpose of following this tutorial the password I have provided does fulfill these criteria. If your password doesn’t meet the requirements, later when you come to run the container, you will get a SqlException complaining that the application couldn’t log in as the sa user. If you get this exception, try modifying the password and trying again.

Thanks for your reply.
Still no luck, still the same issue
api_1              | Could not execute because the specified command or file was not found.
api_1              | Possible reasons for this include:
api_1              |   * You misspelled a built-in dotnet command.
api_1              |   * You intended to execute a .NET program, but dotnet-WebApiSQLServer.dll does not exist.
api_1              |   * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on

how come dotnet comment is appended with my dll dotnet-WebApiSQLServer.dll

Note: i’m using EF core code first approach