1

so, I'm learning and new to Docker and I'm trying to use the docker run command to run an image that is produced from Visual Studio 2017.

Some background:

The aim is to publish a docker image to a Container Registry (I'm using gitlab), create a docker droplet in DigitalOcean and pull the image and run it.

I am trying to build a release image and run it locally first.

I have a VS solution which contains 3 projects:

  • .net core mvc
  • .net core library
  • .net core api

I have a docker compose file and each project has a docker file. All generated by visual studio using the docker support tool.

I can build and run both in debug and release mode in VS and it runs the image and I can browse to both the web app and api - all is okay.

I have tried to follow the answer to this question:

How to run docker image produced by VS 2017

So I have tried:

docker run --rm -p 80:5000 -d myapp.web:latest

And I have tried both http://localhost:5000 and http://127.0.0.1:5000 in a browser and both cannot be loaded or resolved.

I can see the docker images produced by VS below via the docker images command

REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
myapp.apinet                 latest              b3fa6d92bd23        24 hours ago        305MB
myapp.web                    latest              f418d4571ac3        24 hours ago        315MB
<none>                       <none>              50c89857daf1        24 hours ago        315MB

If it helps, one of my docker files:

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY *.sln ./
COPY src/myapp.Web/myapp.Web.csproj src/myapp.Web/
COPY src/myapp.Core/myapp.Core.csproj src/myapp.Core/
RUN dotnet restore
COPY . .
WORKDIR /src/src/myapp.Web
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

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

I have also inspected the docker image using docker inspect myapp.web and port 80 is exposed:

"ExposedPorts": {   
"80/tcp": {}    
},                  

I have tried the asp.net core example from https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetapp as below, and that works fine.

docker run --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp

Any suggestions or ideas?

Chuen Lee
  • 353
  • 4
  • 17

1 Answers1

0

Just trying to isolate problem here. Please bear with me as I work with you here. Will try my best to help:

Q1 Are you using Docker for Windows Pro/Ent or Docker Toolbox for Windows Home? Q2 what version of VS2017 are you using? Did docker come with it pre-installed or you separately installed it? Q3 since you mentioned there’s a docker compose did you try to run the docker-compose up? Q4 have you modified your dockerfile? It just looks odd to me that your dockerfile example is only building web and not core. Also is web referencing core project by any chance? Cuz if it is and it’s not getting compiled then it may not run the web app Q5 (only if you’re using docker toolbox) are you forgetting to use the IP address of your docker-machine ip instead of localhost?

Also look at my response in this article to see if you miss anything. (May not be applicable in your case too!) How to get docker toolbox to work with .net core 2.0 project

BRBdot
  • 758
  • 2
  • 8
  • 20
  • Hi, Q1: Window Pro N. Q2: VS Community 15.5.7, Q3: Have not tried docker-compose up. Could you perhaps provide some tips? Q4: I have modifed the dockerfile - but only to correct the proj names, as I was doing some refactoring. Yes, I have a core proj which both web and api are referencing. The strange thing is that VS is able to run both web and api via docker - just want to figure out what docker cmd it is running behind the scene. I have checked the "build" and "docker" output from the output window. Q5: I don't believe I am using docker toolbox. I am using docker support tools in VS.Thanks – Chuen Lee Mar 09 '18 at 09:52
  • You can view the commands in the docker window when the build starts. I assure they are not different than what you may be doing. – BRBdot Mar 10 '18 at 15:02
  • docker-compose orchestrates a multi dockerfile/container situation. I'd highly advise to use `docker-compose up` in the command line to see if docker engine spins up all your containers and works as expected. – BRBdot Mar 10 '18 at 15:04