aspnet / aspnet-docker

[Archived] ASP.NET Core Docker images for 1.x. Go to https://github.com/dotnet/dotnet-docker for 2.1 and up.
https://asp.net
719 stars 171 forks source link

Can't run docker app in visual studio release mode #369

Closed darius-khll closed 6 years ago

darius-khll commented 6 years ago

I created asp.net core 2 app in visual studio and I enabled docker support, everything works fine, I can run it in visual studio and debug it easily. But after changing to release mode and rebuild solution again, I see another image with latest tag that make sense. After running this command I wish I could using this container by it's port docker run -p 8585:80 webapplication1:latest

Expected behavior

expected to run this docker image successfully

Actual behavior

Error:
  An assembly specified in the application dependencies manifest (WebApplication1.deps.json) was not found:
    package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.1'
    path: 'lib/netstandard2.0/Microsoft.AspNetCore.Antiforgery.dll'
  This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
    aspnetcore-store-2.0.3.xml

Output of dotnet --info

.NET Command Line Tools (2.1.2)

Product Information:
 Version:            2.1.2
 Commit SHA-1 hash:  5695315371

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.2\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

Output of docker info

Containers: 2
 Running: 1
 Paused: 0
 Stopped: 1
Images: 30
Server Version: 18.02.0-ce-rc2
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9b55aab90508bd389d7654c4baf173a981477d55
runc version: 9f9c96235cc97674e935002fc3d78361b696a69e
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.75-linuxkit-aufs
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155dc6012c
ID: M2QL:MAUJ:XEGH:RKMX:T56I:ODUO:HCRT:2YAV:GNAG:ELQM:WJDQ:BMSW
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 27
 Goroutines: 42
 System Time: 2018-02-20T11:34:42.6423604Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
natemcmaster commented 6 years ago

Can you share more information about which images you are using? I suspect you are using microsoft/dotnet when you actually need to use microsoft/aspnetcore. If so, this bug is a duplicate of https://github.com/aspnet/aspnet-docker/issues/286

darius-khll commented 6 years ago

Everything is default and I did not change anything after visual studio docker support tooling added these specific files

Docker file


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

FROM microsoft/aspnetcore-build:2.0 AS build WORKDIR /src COPY *.sln ./ COPY WebApplication1/WebApplication1.csproj WebApplication1/ RUN dotnet restore COPY . . WORKDIR /src/WebApplication1 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", "WebApplication1.dll"]



I just want to start that image manually without visual studio
natemcmaster commented 6 years ago

It's possible your machine has a stale version of the microsoft/aspnetcore:2.0 image. Can you run this to see if it resolves the issue?

docker pull microsoft/aspnetcore:2.0
darius-khll commented 6 years ago

I had that image already, but I pulled it again Unfortunately nothing changed! same error happened.

darius-khll commented 6 years ago

I found a solution to solve the problem, The solution is to add <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> to your csjproj files so the dotnet publish bundles all the required files. something like this:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
  </PropertyGroup>
...