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
19.21k stars 716 forks source link

slim succeeds, but image does not run #475

Open icsy7867 opened 1 year ago

icsy7867 commented 1 year ago

Expected Behavior

Container runs


Actual Behavior

Container does not run


Steps to Reproduce the Problem

This probably has to do with the container i made, but I am not sure where to start for debugging. --- Specifications ================= - Version: 1.40 - Platform: running in gitlab, using docker in docker. So a bit of background... I have a web app build from: php:8.1-apache-bullseye I add a few extra packages, and I compile the php sqlsrv driver from Microsoft. Everything runs fine. After a co-worker mentioned the app, I gave it a shot. `docker-slim build --http-probe=false --sensor-ipc-mode proxy my-tool:8.1-bullseye` (Also tried it with --http-probe=true and the --sensor-ipc-mode because it's running in DIND via gitlab.) Succeeded! Beautiful, tiny, image! However, when I try to test and deploy onto my server, the image immediately crashes. The logs in the container are simply: `mkdir: cannot create directory '/var/lock': File exists` If I change the --http-probe=true, I got a different error: `/bin/sh: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory` im 100% sure this is to do with my container and my lack of understanding with your tool. But i am hoping someone can give me some guidance on steps to problem solve :D Thank you!
e7paul commented 1 year ago

same problem

waaman commented 1 year ago

Hello, same thing also

kcq commented 1 year ago

@waaman are you also trying to minify a php-based app container image?

kcq commented 1 year ago

mkdir: cannot create directory '/var/lock': File exists - setting --include-new to false might have with this potentially, but it'll be good to learn more about the application. Great that we already have the base image info (php:8.1-apache-bullseye). Is this a web server app? What kind of endpoints does it have? If it has endpoints do you have an EXPOSE instruction in your Dockerfile? What port do you use? What does your app do?

waaman commented 1 year ago

Thank you for your reply.

@waaman are you also trying to minify a php-based app container image?

Yes i try to create a slim version of a personal image based on php:8-apache. I don't have enough skills on docker-slim, this is my first try.

Is this a web server app?

Yes it is.

What kind of endpoints does it have?

The base image endpoint: docker-php-entrypoint and CMD apache2-foreground from php:8-apache

do you have an EXPOSE instruction in your Dockerfile?

Yes i have EXPOSE 80 --http-probe=false is mandatory if i want a slim version or the slim process failed.

What does your app do?

The goal is to serve php website but this image is just the server environment

waaman commented 1 year ago

After some tests on several distros i can't slim the php:8-apache base image itself like the first post indicated.

I always get the error

mkdir: cannot create directory '/var/lock': File exists

First step: docker pull php:8-apache

On a Fedora 38 PC:

slim lock exists

On unRAID v6.12.3:

slim lock exists unraid

On Debian:

slim lock exists debian

I tried Slim on an Alpine linux desktop environment but no luck i had Fatal error.

cmd=build info=report file='slim.report.json' 
time="2023-08-23T08:21:39+02:00" level=fatal msg="slim: failure" error="unexpected event type" stack="goroutine 1 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x65\ngithub.com/docker-slim/docker-slim/pkg/util/errutil.FailOn({0x228f340, 0xc0003b2f70})\n\tgithub.com/docker-slim/docker-slim/pkg/util/errutil/errutil.go:32 +0x5e\ngithub.com/docker-slim/docker-slim/pkg/app.(*ExecutionContext).FailOn(0xc0001a02c0?, {0x228f340?, 0xc0003b2f70?})\n\tgithub.com/docker-slim/docker-slim/pkg/app/execontext.go:56 +0x49\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands/build.OnCommand(_, _, {_, _}, _, {_, _}, {_, _}, {0x0, ...}, ...)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/build/handler.go:1120 +0x436b\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands/build.glob..func1(0xc0002e7880)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/build/cli.go:743 +0x5910\ngithub.com/urfave/cli/v2.(*Command).Run(0x3252d40, 0xc0000ad200)\n\tgithub.com/urfave/cli/v2@v2.3.0/command.go:163 +0x5dc\ngithub.com/urfave/cli/v2.(*App).RunContext(0xc000102b60, {0x22ac5b0?, 0xc0000520b8}, {0xc0005e20f0, 0x5, 0x5})\n\tgithub.com/urfave/cli/v2@v2.3.0/app.go:313 +0xb7d\ngithub.com/urfave/cli/v2.(*App).Run(...)\n\tgithub.com/urfave/cli/v2@v2.3.0/app.go:224\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands.(*InteractiveApp).execute(0xc0001ffd70, {0xc0004450e0?, 0xc000536010?})\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/cliprompt.go:101 +0x354\ngithub.com/c-bata/go-prompt.(*Prompt).Run(0xc00034e600)\n\tgithub.com/c-bata/go-prompt@v0.2.3/prompt.go:85 +0x83b\ngithub.com/docker-slim/docker-slim/pkg/app/master/commands.(*InteractiveApp).Run(...)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/commands/cliprompt.go:187\ngithub.com/docker-slim/docker-slim/pkg/app/master.newCLI.func4(0xc0005c66c0?)\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/cli.go:176 +0x50\ngithub.com/urfave/cli/v2.(*App).RunContext(0xc000102b60, {0x22ac5b0?, 0xc0000520b8}, {0xc000050210, 0x1, 0x1})\n\tgithub.com/urfave/cli/v2@v2.3.0/app.go:322 +0x97c\ngithub.com/urfave/cli/v2.(*App).Run(...)\n\tgithub.com/urfave/cli/v2@v2.3.0/app.go:224\ngithub.com/docker-slim/docker-slim/pkg/app/master.Run()\n\tgithub.com/docker-slim/docker-slim/pkg/app/master/app.go:15 +0x46\nmain.main()\n\tgithub.com/docker-slim/docker-slim/cmd/slim/main.go:15 +0x18e\n" version="linux|Transformer|1.40.3|155f1b79556b7d100726f5ef4633f81a6ed27a2b|2023-07-13_07:46:40AM"
licf12138 commented 9 months ago

I got the same problem. php:7.4.14-apache.

kcq commented 7 months ago

try the latest version, 1.40.11, it has a flag to exclude the /var/lock data (--exclude-varlock-files) and the flag is enabled by default.