0

I'm using docker to deploy my web application in my VPS (Ubuntu 18.04).

Here is my Dockerfile

FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app

RUN dotnet restore
RUN dotnet build

EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENV ASPNETCORE_ENVIRONMENT docker

ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "http://*:5000"]

I also use Nginx and it works perfectly (http://www.onserassure.com)

It's already running with SQLite but I wanted to use SQL Server. So I found this tutorial to use SQL Server on Mac/Linux : https://www.phillipsj.net/posts/working-with-sql-server-on-linux-for-dotnet-development And it worked fine. I ran my SQL Server container with :

 docker run -d --name sql_server_demo -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=XXXXX' -p 1433:1433 microsoft/mssql-server-linux

And used this connection string :

"Server=localhost;Database=Movies;User Id=sa;Password=XXXXXXX;"

So it worked fine with a simple dotnet run in local

But when I put my app in a container (even in local), it can't access to my database...

I don't really understand why. I'm testing on my Macbook and my VPS is on Linux

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nemtecl
  • 355
  • 1
  • 3
  • 14
  • Possible duplicate of [How do I fix the error 'Named Pipes Provider, error 40 - Could not open a connection to' SQL Server'?](https://stackoverflow.com/questions/9945409/how-do-i-fix-the-error-named-pipes-provider-error-40-could-not-open-a-connec) – Diogo Rocha Jun 11 '19 at 22:44

1 Answers1

1

So it looks like you have .net core app in a container, and then you run your database in a separate container. If that is so then your connection string won't work in the .net core app container. Localhost inside a container is not the same as localhost of the host machine.

You can try to use host networking to see if this is the issue probably. I remeber the host networking option has some funky behavior with Docker Desktop on mac and windows though. Should be ok if you're on linux.

I would recommend you use something like docker-compose instead though.

Alex
  • 156
  • 3
  • 4