slim icon indicating copy to clipboard operation
slim copied to clipboard

Generates 0B File

Open TimeTravelersHackedMe opened this issue 8 years ago • 18 comments

Hey, I ran through the directions and it gave me a 0B file... what am I missing?

TimeTravelersHackedMe avatar Feb 24 '18 04:02 TimeTravelersHackedMe

Thank you for reporting the problem! Can you provide a bit more context? What's your Docker image? What's in it? What is it supposed to do? What ports is it supposed to expose?

kcq avatar Feb 24 '18 22:02 kcq

Having the same problem!

I downloaded the latest Mac binary: https://github.com/docker-slim/docker-slim/releases/download/1.20/dist_mac.zip, unzipped it in Downloads and ran:

~/D/dist_mac> ./docker-slim build python:3.6.5
docker-slim[build]: state=started
docker-slim[build]: info=params target=python:3.6.5 continue.mode=enter
docker-slim[build]: state=inspecting.image
docker-slim[build]: info=image id=sha256:a5b7afcfdcc878fae7696ea80eecc31114b9c712a1e896cba87a999d255e4a7b size.bytes=911707985 size.human=912 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 [911707985 (912 MB) => 0 (0 B)]'
docker-slim[build]: info=results  image.name=python.slim image.size='0 B' data=false
docker-slim[build]: info=results  artifacts.location='/Users/jacobhagstedt/Downloads/dist_mac/.images/a5b7afcfdcc878fae7696ea80eecc31114b9c712a1e896cba87a999d255e4a7b/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=python-seccomp.json
docker-slim[build]: info=results  artifacts.apparmor=python-apparmor-profile
docker-slim[build]: state=done

The docker-slim outputs that the final image became 0B (the official Python 3.6.5 image) and running docker images shows the same result:

~/D/dist_mac> docker images
REPOSITORY           TAG              IMAGE ID          CREATED           SIZE
python.slim          latest           7868a2bf7752      3 minutes ago     0B
> ./docker-slim --version
docker-slim version darwin|Tetra|1.20|f79fefbb88486f9431fdae5c6f65155fb7b3d39b|2018-03-05_05:20:22AM (go1.10)
> docker --version
Docker version 18.03.1-ce, build 9ee9f40

Jacobh2 avatar Jul 11 '18 14:07 Jacobh2

Anything new on this, I'm having the same problem?

psyhomb avatar Aug 23 '18 11:08 psyhomb

@Jacobh2 thank you for your repro! Note that normally vanilla python images are not great for this type of minification because without the application code the minified image has limited value. I tried to minify python:3.6.5 and I actually got an 18MB image, but it didn't run because of a missing shared library. Will keep trying to repro either way. I'll post more result soon.

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

Ah, so maybe my test was not a good one for this! Thing is, I got this 0B result on my application Dockerfile also, so I just wanted to do a minimal test.

When you run the python:3.6.5 image @q-cloudlock which version of the docker-slim are you running? And under which os?

Jacobh2 avatar Aug 24 '18 07:08 Jacobh2

@Jacobh2 My version is built from the latest source in master. Also looks like the Docker guys decided to compile their python with "--enable-shared" and it caused that missing shared library problem. There'll be a new release as soon as the shared library problem is resolved. Thanks again for reporting this!

kcq avatar Aug 25 '18 16:08 kcq

@Jacobh2 here's what I got with the new version, 1.21 (released today)...

$ docker-slim build python:3.6.5
...
docker-slim[build]: info=results status='MINIFIED BY 50.80X [911710465 (912 MB) => 17946656 (18 MB)]'
docker-slim[build]: info=results  image.name=python.slim image.size='18 MB' data=true
...

$ docker images | grep python.slim
python.slim                                           latest              bf44a665d744        4 minutes ago       17.9MB

$ docker run -it --rm python.slim
...
Python 3.6.5 (default, Jun 27 2018, 08:15:56) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

kcq avatar Aug 26 '18 06:08 kcq

The --debug and --show-clogs flags are useful to get additional debugging information (e.g., docker-slim --debug build --show-clogs your_app_image_here). Can you use those flags minifying your image if you still see the 0 byte problem. Hopefully it'll provide some clues...

kcq avatar Aug 26 '18 06:08 kcq

Awesome, thanks! I will try it out again asap and see if it now works!

Jacobh2 avatar Aug 26 '18 08:08 Jacobh2

I've finally got around to test this!

> ./docker-slim build python:3.6.5 now seems to work! 💯

> ./docker-slim build python:3.6.5
docker-slim[build]: state=started
docker-slim[build]: info=params target=python:3.6.5 continue.mode=enter
docker-slim[build]: state=inspecting.image
docker-slim[build]: info=image id=sha256:9a58cce9b09fab822c803138dca676c24c5644ce0a3c6a78418eb05fdb3f3f5a size.bytes=911710465 size.human=912 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 50.80X [911710465 (912 MB) => 17946656 (18 MB)]'
...
docker-slim[build]: state=done

Also tested on the image that I really wanted to work, but there it fails, but I don't that that has to do with this issue!

Jacobh2 avatar Sep 24 '18 16:09 Jacobh2

What is the image you really wanted to work? What else is there?

The gotcha with minifying a base python image and not your entire application is that it's not going to include a lot of things because docker-slim doesn't know what your app will need. For example, when I minified the python 3.6.5 image it worked and I did see the python prompt and i was able to run basic python commands, but many features/capabilities were not available because they require dynamic code loading and that code wasn't there.

kcq avatar Sep 24 '18 21:09 kcq

Yeah, I think that is the issue which means I won't be able to use this to get my images smaller unfortunately!

For example, my images fail to run because the module chardet.sbcsgroupprober is missing, which is something that is used by the requests lib:

Traceback (most recent call last):
  File "main.py", line 23, in <module>
    from checker import is_time_set
  File "./checker/__init__.py", line 10, in <module>
    from checker.get import get_time
  File "./checker/get.py", line 2, in <module>
    import requests
  File "/usr/local/lib/python3.7/site-packages/requests/__init__.py", line 44, in <module>
    import chardet
  File "/usr/local/lib/python3.7/site-packages/chardet/__init__.py", line 20, in <module>
    from .universaldetector import UniversalDetector
  File "/usr/local/lib/python3.7/site-packages/chardet/universaldetector.py", line 48, in <module>
    from .sbcsgroupprober import SBCSGroupProber
ModuleNotFoundError: No module named 'chardet.sbcsgroupprober'

Jacobh2 avatar Sep 25 '18 09:09 Jacobh2

DockerSlim is not a good option if you want to minify your base python image before you build your application. It is a good option if you build your application image on top of the base python image and then minify that. This way DockerSlim will see that your application is using requests and other dependencies your application needs.

kcq avatar Oct 01 '18 06:10 kcq

Yes, I know. Using the base image was just something I did at the start to see how docker-slim worked :)

The above traceback is from using docker-slim on my image which includes my app! Is there anything specific I can do to make it understand that it shouldn't remove libs that I require? Can I flag them in some way?

Jacobh2 avatar Oct 01 '18 06:10 Jacobh2

What kind of application is it? Is it a command line tool or a server? What's the code path where the app gets to use chardet?

One way to make sure the libraries you need are included is to exercise the code path where they are used. For a api/web server it means triggering the appropriate endpoints in your server (using the http probe commands). For cli applications it means passing the appropriate command line arguments for your app when you run docker-slim build using the --cmd command line argument.

kcq avatar Oct 01 '18 07:10 kcq

There's a low level --include-path command line argument to tell DockerSlim that you want the target directory or file to be included in the minified image. It'll be good to add an application level --ensure-package to avoid having to locate the package directories/files you need manually.

kcq avatar Oct 01 '18 07:10 kcq

Thanks for the help!

I'll see if I can get the time to test this, right now I'm using the 'slim' python image (3.6.6-slim-jessie tag) from the official repo to get a little smaller footprint!

Jacobh2 avatar Oct 01 '18 07:10 Jacobh2

With many scripting languages it's important to make sure you execute the key code paths. This is why the probe parameter exists when you have a service with an HTTP API. It calls the endpoints you want (defaults to the root path) and it executes the relevant app code paths, which load their dependencies. For the command line applications you can accomplish something similar using you application's command line parameter.

kcq avatar Apr 29 '19 01:04 kcq