slim icon indicating copy to clipboard operation
slim copied to clipboard

Docker-slim for dotnet core?

Open uffebjorklund opened this issue 8 years ago • 8 comments

This looks awesome, so I tried ot on one of my images based on microsoft/dotnet:2.1.2-runtime-deps-alpine3.7. It did not crash but gave an output of 0 bytes.

Any plans to support dotnet core based images?

uffebjorklund avatar Aug 22 '18 04:08 uffebjorklund

Absolutely. Do you have a reference to your docker project? Is there another way to repro the condition?

kcq avatar Aug 22 '18 05:08 kcq

That was fast :) Sure will provide a sample on git asap

Thanks!

uffebjorklund avatar Aug 22 '18 05:08 uffebjorklund

That'll be great especially if it's really basic :) Thank you!

kcq avatar Aug 22 '18 06:08 kcq

I think the most basic is this.

EDIT: Link to repo

Pull Microsofts sample application

docker run microsoft/dotnet-samples

Check size (180 MB)

docker images  microsoft/dotnet-samples
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
microsoft/dotnet-samples   latest              1847fea647f0        13 hours ago        180MB

Run docker-slim

./docker-slim build microsoft/dotnet-samples

Output:

docker-slim[build]: state=started
docker-slim[build]: info=params target=microsoft/dotnet-samples continue.mode=enter
docker-slim[build]: state=inspecting.image
docker-slim[build]: info=image id=sha256:1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5 size.bytes=180239958 size.human=180 MB
docker-slim[build]: state=inspecting.container
docker-slim[build]: info=prompt message='press <enter> when you are done using the container'

docker-slim[build]: state=processing
docker-slim[build]: state=building message='building minified image'
docker-slim[build]: state=completed
docker-slim[build]: info=results status='MINIFIED BY +InfX [180239958 (180 MB) => 0 (0 B)]'
docker-slim[build]: info=results  image.name=microsoft/dotnet-samples.slim image.size='0 B' data=false
docker-slim[build]: info=results  artifacts.location='/Users/sir/docker-slim/.images/1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5/artifacts'
docker-slim[build]: info=results  artifacts.report=creport.json
docker-slim[build]: info=results  artifacts.dockerfile.original=Dockerfile.fat
docker-slim[build]: info=results  artifacts.dockerfile.new=Dockerfile
docker-slim[build]: info=results  artifacts.seccomp=microsoft-dotnet-samples-seccomp.json
docker-slim[build]: info=results  artifacts.apparmor=microsoft-dotnet-samples-apparmor-profile
docker-slim[build]: state=done

Check result (even though we could see that it was 0 bytes in the log)

docker images microsoft/dotnet-samples.slim
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
microsoft/dotnet-samples.slim   latest              f6a697ad51e3        4 minutes ago       0B

uffebjorklund avatar Aug 22 '18 07:08 uffebjorklund

Is this problem possibly related to #46?

Jacobh2 avatar Aug 23 '18 21:08 Jacobh2

Not sure if it is related... Can you run it with debugging turned on: ./docker-slim --debug build microsoft/dotnet-samples

q-cloudlock avatar Aug 24 '18 05:08 q-cloudlock

./docker-slim --debug build microsoft/dotnet-samples

Output

docker-slim[build]: state=started
docker-slim[build]: info=params target=microsoft/dotnet-samples continue.mode=enter
time="2018-08-24T09:10:28+02:00" level=info msg="image=microsoft/dotnet-samples http-probe=false remove-file-artifacts=false image-overrides=map[] entrypoint=[] (false) cmd=[] (false) workdir='' env=[] expose=map[]" app=docker-slim command=build 
time="2018-08-24T09:10:28+02:00" level=debug msg="docker-slim: new Docker client (default) [6]" 
time="2018-08-24T09:10:28+02:00" level=debug msg="docker-slim: configured DOCKER_HOST env var" 
docker-slim:
darwin|Tetra|1.20|f79fefbb88486f9431fdae5c6f65155fb7b3d39b|2018-03-05_05:20:22AM (go1.10)
host:
system.SystemInfo{Sysname:"darwin", Nodename:"Uffes-MacBook-Pro.local", Release:"17.6.0", Version:" Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64", Machine:"x86_64", Domainname:"", OsName:"High Sierra (10.13.6)", OsBuild:"17F77"}
docker:
Name=linuxkit-025000000001
KernelVersion=4.9.93-linuxkit-aufs
OperatingSystem=Docker for Mac
OSType=linux
ServerVersion=18.06.0-ce
Architecture=x86_64
ApiVersion=1.38
MinAPIVersion=1.12
BuildTime=2018-07-18T19:13:46.000000000+00:00
GitCommit=0ffa825
docker-slim[build]: state=inspecting.image
time="2018-08-24T09:10:28+02:00" level=info msg="inspecting 'fat' image metadata..." app=docker-slim command=build 
time="2018-08-24T09:10:28+02:00" level=debug msg="PrepareStateDirs(,sha256:1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5)" 
time="2018-08-24T09:10:28+02:00" level=debug msg="PrepareStateDirs - removing existing state location: /Users/sir/docker-slim/.images/1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5/artifacts" 
time="2018-08-24T09:10:28+02:00" level=debug msg="PrepareStateDirs - created new state location: /Users/sir/docker-slim/.images/1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5/artifacts" 
docker-slim[build]: info=image id=sha256:1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5 size.bytes=180239958 size.human=180 MB
time="2018-08-24T09:10:28+02:00" level=info msg="processing 'fat' image info..." app=docker-slim command=build 
time="2018-08-24T09:10:28+02:00" level=debug msg="

IMAGE HISTORY =>
[]docker.ImageHistory{docker.ImageHistory{ID:"sha256:1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5", Tags:[]string{"microsoft/dotnet-samples:latest"}, Created:1534875929, CreatedBy:"/bin/sh -c #(nop)  ENTRYPOINT [\"dotnet\" \"dotnetapp.dll\"]", Size:0, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534875928, CreatedBy:"/bin/sh -c #(nop) COPY dir:e4be991e40e2f9943f1586764216bd5ac2fa0030c075c00b9f1fa8f228d12089 in ./ ", Size:15600, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534875928, CreatedBy:"/bin/sh -c #(nop) WORKDIR /app", Size:0, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534801608, CreatedBy:"/bin/sh -c curl -SL --output dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$DOTNET_VERSION/dotnet-runtime-$DOTNET_VERSION-linux-x64.tar.gz     && dotnet_sha512='e2a9a25436744498ee827125083e41151e90e914091863d396ff8d3916467e8ebef4cdfe5c97a13381e6d257d1e01b7a02f846b9c8406643848e3d433d6bd60a'     && echo \"$dotnet_sha512 dotnet.tar.gz\" | sha512sum -c -     && mkdir -p /usr/share/dotnet     && tar -zxf dotnet.tar.gz -C /usr/share/dotnet     && rm dotnet.tar.gz     && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet", Size:74219994, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534801596, CreatedBy:"/bin/sh -c #(nop)  ENV DOTNET_VERSION=2.1.3", Size:0, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534801595, CreatedBy:"/bin/sh -c apt-get update     && apt-get install -y --no-install-recommends         curl     && rm -rf /var/lib/apt/lists/*", Size:7020445, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534801578, CreatedBy:"/bin/sh -c #(nop)  ENV ASPNETCORE_URLS=http://+:80 DOTNET_RUNNING_IN_CONTAINER=true", Size:0, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1534801577, CreatedBy:"/bin/sh -c apt-get update     && apt-get install -y --no-install-recommends         ca-certificates                 libc6         libgcc1         libgssapi-krb5-2         libicu57         liblttng-ust0         libssl1.0.2         libstdc++6         zlib1g     && rm -rf /var/lib/apt/lists/*", Size:43713702, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1531787284, CreatedBy:"/bin/sh -c #(nop)  CMD [\"bash\"]", Size:0, Comment:""}, docker.ImageHistory{ID:"<missing>", Tags:[]string(nil), Created:1531787284, CreatedBy:"/bin/sh -c #(nop) ADD file:919939fa022472751b717443eea9f1d7ab5c0723f1f3a6b776d3b83d22bde818 in / ", Size:55270217, Comment:""}}

" 
time="2018-08-24T09:10:28+02:00" level=debug msg="IMAGE INSTRUCTIONS:" 
time="2018-08-24T09:10:28+02:00" level=debug msg="# new image" 
time="2018-08-24T09:10:28+02:00" level=debug msg="ADD file:919939fa022472751b717443eea9f1d7ab5c0723f1f3a6b776d3b83d22bde818 in / " 
time="2018-08-24T09:10:28+02:00" level=debug msg=" CMD ["bash"]" 
time="2018-08-24T09:10:28+02:00" level=debug msg="RUN apt-get update && \
	apt-get install -y --no-install-recommends         ca-certificates                 libc6         libgcc1         libgssapi-krb5-2         libicu57         liblttng-ust0         libssl1.0.2         libstdc++6         zlib1g && \
	rm -rf /var/lib/apt/lists/*" 
time="2018-08-24T09:10:28+02:00" level=debug msg=" ENV ASPNETCORE_URLS=http://+:80 DOTNET_RUNNING_IN_CONTAINER=true" 
time="2018-08-24T09:10:28+02:00" level=debug msg="RUN apt-get update && \
	apt-get install -y --no-install-recommends         curl && \
	rm -rf /var/lib/apt/lists/*" 
time="2018-08-24T09:10:28+02:00" level=debug msg=" ENV DOTNET_VERSION=2.1.3" 
time="2018-08-24T09:10:28+02:00" level=debug msg="RUN curl -SL --output dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$DOTNET_VERSION/dotnet-runtime-$DOTNET_VERSION-linux-x64.tar.gz && \
	dotnet_sha512='e2a9a25436744498ee827125083e41151e90e914091863d396ff8d3916467e8ebef4cdfe5c97a13381e6d257d1e01b7a02f846b9c8406643848e3d433d6bd60a' && \
	echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - && \
	mkdir -p /usr/share/dotnet && \
	tar -zxf dotnet.tar.gz -C /usr/share/dotnet && \
	rm dotnet.tar.gz && \
	ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet" 
time="2018-08-24T09:10:28+02:00" level=debug msg="WORKDIR /app" 
time="2018-08-24T09:10:28+02:00" level=debug msg="COPY dir:e4be991e40e2f9943f1586764216bd5ac2fa0030c075c00b9f1fa8f228d12089 in ./ " 
time="2018-08-24T09:10:28+02:00" level=debug msg=" ENTRYPOINT ["dotnet" "dotnetapp.dll"]" 
time="2018-08-24T09:10:28+02:00" level=debug msg="# end of image: microsoft/dotnet-samples (id: sha256:1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5 tags: latest)" 
time="2018-08-24T09:10:28+02:00" level=debug 
docker-slim[build]: state=inspecting.container
time="2018-08-24T09:10:28+02:00" level=info msg="starting instrumented 'fat' container..." app=docker-slim command=build 
time="2018-08-24T09:10:28+02:00" level=info msg="docker-slim: created container => aa9b82c8f7e0f5e55a5561c79b5132d658ac5de000d14832a6f9d087f42d9de6" 
time="2018-08-24T09:10:29+02:00" level=debug msg="container NetworkSettings.Ports => map[docker.Port][]docker.PortBinding{"65501/tcp":[]docker.PortBinding{docker.PortBinding{HostIP:"0.0.0.0", HostPort:"32769"}}, "65502/tcp":[]docker.PortBinding{docker.PortBinding{HostIP:"0.0.0.0", HostPort:"32768"}}}" 
time="2018-08-24T09:10:29+02:00" level=debug msg="cmdChannelAddr=tcp://127.0.0.1:32769 evtChannelAddr=tcp://127.0.0.1:32768" 
time="2018-08-24T09:10:29+02:00" level=debug msg="sendCmd(&{dotnet [dotnetapp.dll] [] []})" 
time="2018-08-24T09:10:29+02:00" level=info msg="watching container monitor..." app=docker-slim command=build 
docker-slim[build]: info=prompt message='press <enter> when you are done using the container'

time="2018-08-24T09:10:41+02:00" level=debug msg="sendCmd(&{})" 
time="2018-08-24T09:10:41+02:00" level=debug msg="'stop' monitor response => 'ok'" 
time="2018-08-24T09:10:41+02:00" level=info msg="docker-slim: waiting for the container to finish its work..." 
time="2018-08-24T09:10:41+02:00" level=debug msg="getEvt()" 
time="2018-08-24T09:10:41+02:00" level=debug msg="getEvt(): channel.Recv() - done" 
time="2018-08-24T09:10:41+02:00" level=debug msg="sensor event => 'event.monitor.stop.done'" 
time="2018-08-24T09:10:41+02:00" level=debug msg="docker-slim: sensor event => 'event.monitor.stop.done'" 
time="2018-08-24T09:10:41+02:00" level=debug msg="sendCmd(&{})" 
time="2018-08-24T09:10:41+02:00" level=debug msg="'shutdown' sensor response => 'ok'" 
time="2018-08-24T09:10:41+02:00" level=info msg="shutting down 'fat' container..." app=docker-slim command=build 
docker-slim[build]: state=processing
time="2018-08-24T09:10:42+02:00" level=info msg="processing instrumented 'fat' container info..." app=docker-slim command=build 
time="2018-08-24T09:10:42+02:00" level=info msg="docker-slim: generating AppArmor profile..." 
time="2018-08-24T09:10:42+02:00" level=debug msg="docker-slim: saving seccomp profile to /Users/sir/docker-slim/.images/1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5/artifacts/microsoft-dotnet-samples-seccomp.json" 
docker-slim[build]: state=building message='building minified image'
time="2018-08-24T09:10:42+02:00" level=info msg="WARNING - no data artifacts" app=docker-slim command=build 
docker-slim[build]: state=completed
docker-slim[build]: info=results status='MINIFIED BY +InfX [180239958 (180 MB) => 0 (0 B)]'
docker-slim[build]: info=results  image.name=microsoft/dotnet-samples.slim image.size='0 B' data=false
docker-slim[build]: info=results  artifacts.location='/Users/sir/docker-slim/.images/1847fea647f006965f366fc4617dc989551ca6fb389848e84af1609c01fe2ca5/artifacts'
docker-slim[build]: info=results  artifacts.report=creport.json
docker-slim[build]: info=results  artifacts.dockerfile.original=Dockerfile.fat
docker-slim[build]: info=results  artifacts.dockerfile.new=Dockerfile
docker-slim[build]: info=results  artifacts.seccomp=microsoft-dotnet-samples-seccomp.json
docker-slim[build]: info=results  artifacts.apparmor=microsoft-dotnet-samples-apparmor-profile
docker-slim[build]: state=done

uffebjorklund avatar Aug 24 '18 07:08 uffebjorklund

I had a bit more luck with the newly released version (1.21). I managed to generate a minified image (63MB down from the original 180MB), but I'm getting this error when I'm trying to run the minified image:

  An assembly specified in the application dependencies manifest (Microsoft.NETCore.App.deps.json) was not found:
    package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.1.3'
    path: 'runtimes/linux-x64/lib/netcoreapp2.1/Microsoft.CSharp.dll'

Investigating... Looks like some of the dlls in the /usr/share/dotnet/shared/Microsoft.NETCore.App/2.1.3 directory are missing (including Microsoft.CSharp.dll).

kcq avatar Aug 27 '18 02:08 kcq