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

Multi-image build seems to produce unexpected results. #353

Closed KevinBurton closed 6 years ago

KevinBurton commented 6 years ago

Steps to reproduce the issue

I have a Dockerfile like:

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

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build (then throw this image away)
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", "Ng2AspCore.dll"]
# docker run --name aspnetapp -p 80:80 -d ng2aspcore:latest

This gives me the following:

REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
ng2aspcore                   latest              88bd90efee80        5 minutes ago       312MB
<none>                       <none>              fe9f491d5b07        5 minutes ago       2.28GB
microsoft/aspnetcore-build   2.0                 6105426f13e9        8 days ago          1.97GB
microsoft/aspnetcore         2.0                 bb8bdc966bb5        8 days ago          302MB

I shouldn't need the "build" image so I issue the command docker rmi 61

Expected behavior

Remove the image.

Actual behavior

Error response from daemon: conflict: unable to delete 6105426f13e9 (cannot be forced) - image has dependent child images

In addition I am not sure why the intermediate image \<none>:\<none> is there.

Output of dotnet --info

.NET Command Line Tools (2.1.3)

Product Information:
 Version:            2.1.3
 Commit SHA-1 hash:  a0ca411ca5

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.3/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.4
  Build    : 7f262f453d8c8479b9af91d34c013b3aa05bc1ff

Output of docker info

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 10
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 Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: HQVQ:4GA5:2G2K:T22Q:KN3P:AAY6:QC7Z:WFBN:VT4A:SRGB:RGSX:U3L7
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 41
 System Time: 2018-01-18T07:20:10.520680184Z
 EventsListeners: 2
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
MichaelSimons commented 6 years ago

@KevinBurton - When a multi-stage Dockerfile is built, each stage produces an image that is not tagged (e.g. <none>). This image is what has a dependency on microsoft/aspnetcore-build. If you remove the <none> first, you will then be able to remove microsoft/aspnetcore-build. The following docker issue describes this in a little more detail - https://github.com/moby/moby/issues/34151.

In summary this is the designed behavior of Docker and is not something specific to microsoft/aspnetcore-build.

natemcmaster commented 6 years ago

Closing. As @MichaelSimons said, this is the designed behavior of Docker.