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

dotnet pack + docker #360

Closed Drewster727 closed 6 years ago

Drewster727 commented 6 years ago

Guys,

I'm having an interesting issue regarding my aspnetcore 2 app with my CI/CD pipeline. Here's the facts:

Steps to reproduce the issue

dotnet pack the project,

I get the following inside the nupkg. Notice no .cs files (because it's been built). image

upload nupkg to Octopus, deploy the files to a server, then try to use the following Dockerfile:

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
USER root

# Copy csproj and restore as distinct layers
COPY *.csproj package.json ./

RUN npm cache clean -f \
    && npm install -g n \
    && n lts \
    && npm install -g @angular/cli@1.6.3 webpack --unsafe \ 
    && npm install

WORKDIR /app
RUN dotnet restore

COPY . .
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Web.dll"]

image

This dockerfile fails when building on the "RUN dotnet restore" line, which I understand is because it cannot find a .csproj to restore from. OK, so if I start over and include my .csproj via an include (in the csproj itself w/ "pack" set to true), it'll get added.

  <ItemGroup>
    <Content Include="*.csproj">
      <Pack>true</Pack>
    </Content>
  </ItemGroup>

So, if I retry this. I get a little bit further. I now build my docker again and this time I have the csproj inside the nuget. This time it restores everything, and I get to the "RUN dotnet publish -c Release -o out" line. It fails: image

It would appear it's missing my .cs files in order to build.

OK -- at this point it seems clear that maybe I don't NEED to run dotnet publish in my dockerfile? If I comment that out, the docker build succeeds. When I go to run it, I get:

> docker run -it --privileged -p 81:80 drewtest:1
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
  http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

I understand that if I've already "packed" my app it is essentially building it and I don't need to do that again, but I cannot get the app to run inside the docker if I skip those steps.

You're probably asking why don't you just docker build locally and push it to your docker repo. I'm not doing that because that's outside my CI/CD pipeline. I need octopus to handle transformations first.

Output of dotnet --info

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

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

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

Output of docker info

Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 14
Server Version: 17.12.0-ce
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: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.60-linuxkit-aufs
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155dbd1809
ID: BWGU:CGV7:KFKC:BMWR:TOM3:SHJK:DSVN:MEDE:V7RJ:MO6R:GE5H:KLDU
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 27
 Goroutines: 50
 System Time: 2018-01-29T15:44:38.4441821Z
 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

@Drewster727 I'm not sure I understand what you're asking. Forgive my ignorance - I don't know anything about Octopus deploy. What exactly is the problem you're having with our docker container?

Drewster727 commented 6 years ago

@natemcmaster no worries, I fought with it like all day and got it resolved.

For anyone that might need this: I ended up:

No need for dotnet restore/publish inside the container if you follow those steps.