0

I have the following docker file in Visual studio:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 1433

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["src", ""]
COPY ["NuGet.Config", ""]
COPY ["test", "test"]
COPY ["*.sln", ""]

#RUN dotnet restore --configfile NuGet.Config  "Security.WebApi/Security.WebApi.csproj"
COPY . .
WORKDIR "/src/src/WebApi.WebApi"
RUN dotnet build "WebApi.WebApi.csproj" -c Release -o /app/build

#### Run all tests in sln   ####
WORKDIR /src
RUN dotnet test "HSB.Webapi.sln" "--logger:trx"
WORKDIR "/src/src/Webapi.WebApi"
#### END OF TESTS ####

FROM build AS publish
RUN dotnet publish "Webapi.WebApi.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Webapi.WebApi.dll"]

This gives me a container where I can build and run my .NET application.

However, now I want to install SQL Express as well. How can I do this in the docker file above? I want to install and start sql express when the container is started.

I have tried to add this:

FROM microsoft/mssql-server-linux:latest
COPY ./create-db.sql .
ENV ACCEPT_EULA Y
ENV sa_password fisk1234
ENV MSSQL_TCP_PORT=1433
CMD /opt/mssql/bin/sqlservr

But that don't work.

3
  • The best practice is to run the two (web server, database) in different containers, but manage them together. Tons of articles on the right approach, rominirani.com/… Commented May 10, 2020 at 14:29
  • 1
    At least the question you have since deleted told us what the error was. "that don't work" tells us nothing about why or how what you do isn't working (as you expect). Considering you've omited that inforamtion, however, I assume that the results are different. Deleting and reposting questions isn't really what SO is for though. There is an edit feature you should be making use of if you want to improve your question. Commented May 10, 2020 at 14:30
  • @Larnu: Sorry for that. The error was that I could not connect to the database. When I "loged in" to my container, it seemd like database-server was not installed. Commented May 10, 2020 at 14:44

1 Answer 1

2

In short, you can't add another FROM to your main dockerfile to install Sql Server, because that create new layer in temporary image and drop all its previous layers.

So you have two choices:

  1. Install Sql Server with apt-get command in final layer of your docker file using RUN command (not recommended):

    sudo apt-get install mssql-server=(version_number)
    
    // and many more startup configurations ...
    
  2. Use Docker Compose as described in Docker documentation sample (straight and recommended)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.