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.59k stars 736 forks source link

Unusable resultant CentOS image #132

Open snnwolf opened 4 years ago

snnwolf commented 4 years ago

I using centos image link next:

docker build -t t2/bo .
docker-slim build t2/bo:centos
docker images
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
t2/bo.slim                                       latest              37672c536b6e        5 minutes ago       7.04MB
t2/bo                                            centos              df08fdd856fe        57 minutes ago      1.04GB

docker-slim -v
docker-slim version linux|Transformer|1.26.1|2ec04e169b12a87c5286aa09ef44eac1cea2c7a1|2019-11-28_04:37:59PM

With command docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock dslim/docker-slim build t2/bo:centos I have same issue.

dive show next images:

dive t2/bo:centos

Screenshot_20200219_141543

dive t2/bo.slim

Screenshot_20200219_141412

Result: I have no any system/installed programs like sudo, pm2...

slim report: slim.report.json.gz

dive report: t2-bo.tar.gz

kcq commented 4 years ago

Thank you for opening the ticket! I'd love to learn more about your image and your use cases, so we can figure out what can be done. I noticed you install node.js and pm2 and I also noticed the expose Dockerfile instruction. Is there an app hiding somewhere or is it just a base image?

snnwolf commented 4 years ago

Yes, is external app with mount point. This is docker-compose.ini:

version: '3.1'

services:
  prodcat:
    image: t2/bo
    restart: "no"
    working_dir: /app
    user: "bercut"
    volumes:
      - "/home/$USER/.ssh:/home/bercut/.ssh:ro"
      - "./:/app"
    environment:
        REDIS_HOST: "redis"
    command: >
               sudo ssh -f -N -L 5080:192.168.17.98:5080 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnec
               sudo ssh -f -N -L 8083:192.168.6.33:8083 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnect
               sudo ssh -f -N -L 8100:192.168.12.194:8100 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConne
               pm2-dev start ecosystem.config.js --env local"
kcq commented 4 years ago

@snnwolf Thanks for the extra details! It's definitely helpful! I'm curious about the app design and how those ssh commands are related to what the app is doing.

This is an interesting setup for a few reasons (e.g., mounting the app code).

Either way, with a setup like this you also need to tell docker-slim about the runtime parameters you have in your compose file, so the docker-slim command would look something like this: docker-slim build t2/bo --mount '/home/$USER/.ssh:/home/bercut/.ssh:ro' --mount './:/app' --env 'REDIS_HOST=redis' --workdir=/app. Can you try that to see what you get this time?

snnwolf commented 4 years ago

Report with different parameters: https://pastebin.com/pMrzzuZx PS: docker-slim from release

$ dive t2/bo

Screenshot_20200226_104954

snnwolf commented 4 years ago

Report with docker-slim from git: https://pastebin.com/CLbKQjJD dive result is same: size 7.1 Mb

kcq commented 4 years ago

@snnwolf Thanks for retesting! Sorry, just realized that I missed the cmd part of the command in my last comment... Can you try running this command: docker-slim build --mount '/home/$USER/.ssh:/home/bercut/.ssh:ro' --mount './:/app' --env 'REDIS_HOST=redis' --workdir=/app --cmd 'pm2-dev start ecosystem.config.js --env local' t2/bo

Either way, let me try to repro the condition with a similar design too...

snnwolf commented 4 years ago

Greate! It's work in simple running! I will testing in long time working! Thanks! Good work!!! Report log (pastebin) & slim.report.json.gz

Screenshot_20200227_003127

BTW params for your command working with double quote (") not sinle ('):

docker-slim build --mount "/home/$USER/.ssh:/home/bercut/.ssh:ro" --mount "$(pwd):/app" --env 'REDIS_HOST=redis'--workdir=/app --cmd 'pm2-dev start ecosystem.config.js --env local' t2/bo

In other variants I look at error report

PS. Sorry, not all working :( I was try running multi commands by

    command: >
        bash -c "sudo ssh -f -N -L 80:apimnsms.bercut.com:80 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnectTimeout=3 &&
               sudo ssh -f -N -L 4711:192.168.17.146:4711 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnectTimeout=3 &&
               sudo ssh -f -N -L 5080:192.168.17.98:5080 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnectTimeout=3 &&
               sudo ssh -f -N -L 8083:192.168.6.33:8083 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnectTimeout=3 &&
               sudo ssh -f -N -L 8100:192.168.12.194:8100 bercut@192.168.6.41 -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnectTimeout=3 &&
               pm2-dev start ecosystem.config.js --env local"
ERROR: for prodcat  Cannot start service prodcat: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown

PS2. I'm so sorry. It's working with run build with multicommand. Thanks. 🙏🙏🙏

docker-slim build --mount "/home/$USER/.ssh:/home/bercut/.ssh:ro" --mount "$(pwd):/app" \
--env 'REDIS_HOST=redis' --workdir=/app \
--cmd 'sh -c "sudo ssh -q 192.168.6.41 -l bercut -i /home/bercut/.ssh/identity -oBatchMode=yes -oStrictHostKeyChecking=no -oConnectTimeout=3 \"echo 'ok'; exit\" && pm2-dev start ecosystem.config.js --env local"' t2/bo
snnwolf commented 4 years ago

I have erron in other Docker image. On build I copy *.sh files from big archive. With one of them on starting calling cat like

cat /dev/null > "$CATALINA_PID"

Looks like /opt/BERClwsa/bin/catalina.sh: line 348: cat: command not found catalina.sh runing with ENTRYPOINT command My params for build slim image:

PS_DOCKER="/home/$USER/work/bercut/PS/SA ProductShowcase API/docker" docker-slim build --mount "${PS_DOCKER}/../out/artifacts:/app" --mount "${PS_DOCKER}/data:/data" --env local --entrypoint="/tmp/nosv_bootstrap.sh" t2/ps

slim.report.ps2.json.gz Image looks great (about 155 Mb). But sad mistrakes... :(

And run:

PS_DOCKER="/home/$USER/work/bercut/PS/SA ProductShowcase API/docker" docker run -it --rm -v "${PS_DOCKER}/../out/artifacts:/app" -v "${PS_DOCKER}/data:/data" t2/ps.slim