slimtoolkit / slim

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)
Apache License 2.0
18.98k stars 707 forks source link

docker-slim issue when trying to slim a docker image #517

Open sureshkachwa opened 1 year ago

sureshkachwa commented 1 year ago

The actual command to build the docker image is docker build --network=host -t moon:${VERSION} The command executed to slim the image is docker-slim build --target moon:${VERSION} --tag moon:${VERSION} --http-probe=false --include-path / can target and tag have the same value?


The expected behavior is to slim the image while not replacing any file or folder from the actual image


Steps to Reproduce the Problem

Below is the error: ```message='YOU CAN USE THESE PORTS TO INTERACT WITH THE CONTAINER' cmd=build info=continue.after mode='enter' message='provide the expected input to allow the container inspector to continue its execution' cmd=build prompt='USER INPUT REQUIRED, PRESS WHEN YOU ARE DONE USING THE CONTAINER' cmd=build state=container.inspection.finishing time="2023-05-10T15:16:19+05:30" level=error msg="ipc.Client.GetEvent(): event channel error = EOF\n" time="2023-05-10T15:16:19+05:30" level=warning msg="docker-slim: warning" error=EOF stack="goroutine 1 [running]:\nruntime/debug.Stack(0x0, 0xc0005962e0, 0x533665)\n\truntime/debug/stack.go:24 +0x9f\ngithub.com/docker-slim/docker-slim/pkg/util/errutil.WarnOn(0xfca5e0, 0xc000072040)\n\tgithub.com/docker-slim/docker-slim/pkg/util/errutil/errutil.go:38 +0x54\ngithub.com/docker-slim/docker-slim/pkg/app/master/inspectors/container.(*Inspector).FinishMonitoring(0xc0004abb00)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/inspectors/container/container_inspector.go:1104 +0x271\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands/build.OnCommand(0xc0004f6960, 0xc0004c74f0, 0x7fffb8799b44, 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/build/handler.go:1079 +0x409d\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands/build.glob..func1(0xc00047b4a0, 0x0, 0xc0004b36f0)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/build/cli.go:629 +0x321b\ngithub.com/urfave/cli.HandleAction(0xd2e100, 0xeca9b0, 0xc00047b4a0, 0xc00047b4a0, 0x0)\n\tgithub.com/urfave/cli@v1.22.4/app.go:526 +0xfd\ngithub.com/urfave/cli.Command.Run(0xe824d9, 0x5, 0x0, 0x0, 0x1564aa0, 0x1, 0x1, 0xebe395, 0x6c, 0x0, ...)\n\tgithub.com/urfave/cli@v1.22.4/command.go:174 +0x58e\ngithub.com/urfave/cli.(*App).Run(0xc0003656c0, 0xc000030090, 0x9, 0x9, 0x0, 0x0)\n\tgithub.com/urfave/cli@v1.22.4/app.go:279 +0x7e8\ngithub.com/docker-slim/docker-slim/pkg/app/master.Run()\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/app.go:15 +0x54\nmain.main()\n\tgithub.com/docker-slim/docker-slim/cmd/docker-slim/main.go:8 +0x25\n" version="linux|Transformer|1.37.3|97eb3c8c7f8c4e295a26c13882feb3f0539ab50f|2021-12-10_09:37:29AM" time="2023-05-10T15:16:19+05:30" level=error msg="channel.CommandClient.Call: c.Read error = EOF" time="2023-05-10T15:16:19+05:30" level=error msg="ipc.Client.SendCommand() cmd channel call error=EOF\n" time="2023-05-10T15:16:19+05:30" level=error msg="dockerutil.CopyFromContainer: dclient.DownloadFromContainer() error = API error (404): Could not find the file /opt/dockerslim/artifacts/creport.json in container 08dd4c141ff290a918cd791874f796cb58683e3c207d25242995bea860c9eaad" time="2023-05-10T15:16:19+05:30" level=fatal msg="docker-slim: failure" error="API error (404): Could not find the file /opt/dockerslim/artifacts/creport.json in container 08dd4c141ff290a918cd791874f796cb58683e3c207d25242995bea860c9eaad" stack="goroutine 1 [running]:\nruntime/debug.Stack(0xc000050800, 0xc000596260, 0x419c85)\n\truntime/debug/stack.go:24 +0x9f\ngithub.com/docker-slim/docker-slim/pkg/util/errutil.FailOn(0xfca900, 0xc0005025c0)\n\tgithub.com/docker-slim/docker-slim/pkg/util/errutil/errutil.go:28 +0x54\ngithub.com/docker-slim/docker-slim/pkg/app/master/inspectors/container.(*Inspector).ShutdownContainer(0xc0004abb00, 0x4, 0xc000596e00)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/inspectors/container/container_inspector.go:1023 +0x65a\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands/build.OnCommand(0xc0004f6960, 0xc0004c74f0, 0x7fffb8799b44, 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/build/handler.go:1082 +0x410f\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands/build.glob..func1(0xc00047b4a0, 0x0, 0xc0004b36f0)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/build/cli.go:629 +0x321b\ngithub.com/urfave/cli.HandleAction(0xd2e100, 0xeca9b0, 0xc00047b4a0, 0xc00047b4a0, 0x0)\n\tgithub.com/urfave/cli@v1.22.4/app.go:526 +0xfd\ngithub.com/urfave/cli.Command.Run(0xe824d9, 0x5, 0x0, 0x0, 0x1564aa0, 0x1, 0x1, 0xebe395, 0x6c, 0x0, ...)\n\tgithub.com/urfave/cli@v1.22.4/command.go:174 +0x58e\ngithub.com/urfave/cli.(*App).Run(0xc0003656c0, 0xc000030090, 0x9, 0x9, 0x0, 0x0)\n\tgithub.com/urfave/cli@v1.22.4/app.go:279 +0x7e8\ngithub.com/docker-slim/docker-slim/pkg/app/master.Run()\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/app.go:15 +0x54\nmain.main()\n\tgithub.com/docker-slim/docker-slim/cmd/docker-slim/main.go:8 +0x25\n" version="linux|Transformer|1.37.3|97eb3c8c7f8c4e295a26c13882feb3f0539ab50f|2021-12-10_09:37:29AM" ``` --- Specifications ================= - Version: 1.37 - Platform: docker slim is installed in oracle linux 7.9
kcq commented 1 year ago

@sureshkachwa looks like there's potentially a number of different issues there. First of all, including the root directory (with --include-path /) is not supported at this point in time. When the main app sees / as an include it ignores it (there should be a console message saying that the / include is ignored). The error snippet you shared show IPC errors, which might happen if the temporary container isn't running anymore. It's possible it crashed. Looking at the temporary container logs might provide additional clues.

It's also not quite clear what you are trying to accomplish. Do you mind sharing a bit of context for your setup? Why are you using slim if you don't need to slim the image?

sureshkachwa commented 1 year ago

@kcq to be more specific The standard dockerfile uses tomcat as the base image with few RUN,COPY,ARGS and one CMD instruction as well. The COPY instruction does copy our application war file to /usr/local/tomcat and docker-slim is removing it. I am trying to slim the image without losing the image purpose. I also see that the docker-slim is removing the standard ls,cat commands as well. I also tried docker-slim build --target kk:10.1 --tag kk:10.1 --include-path /usr/local/tomcat --http-probe=false But still docker-slim is removing the webapps folder under /usr/local/tomcat and I see go libraries in this location

sureshkachwa commented 1 year ago

@kcq to be more specific The standard dockerfile uses tomcat as the base image with few RUN,COPY,ARGS and one CMD instruction as well. The COPY instruction does copy our application war file to /usr/local/tomcat and docker-slim is removing it. I am trying to slim the image without losing the image purpose. I also see that the docker-slim is removing the standard ls,cat commands as well. I also tried docker-slim build --target kk:10.1 --tag kk:10.1 --include-path /usr/local/tomcat --http-probe=false But still docker-slim is removing the webapps folder under /usr/local/tomcat and I see go libraries in this location

kcq commented 1 year ago

Thank you for the additional context @sureshkachwa ! It's great that you have a CMD instruction. What does it look like? Can you also share an example of your docker run command when you run your tomcat app image?

'ls', 'cat' and many other shell related components get removed by default. You can use the --include-shell command that will allow you to keep the basic parts of your shell. You can also use the --include-exe and --include-bin to make sure you keep other image apps.

sureshkachwa commented 1 year ago

@kcq sure, I'll give it a try and share the command as well

lightnessofbein commented 9 months ago

@sureshkachwa Hey, do you have updates by any chance?

sureshkachwa commented 9 months ago

I haven't worked on it yet, Let me try and update here.