Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Slim to minify docker image #1550

Closed
pourmand1376 opened this issue Jul 11, 2023 · 14 comments
Closed

Using Slim to minify docker image #1550

pourmand1376 opened this issue Jul 11, 2023 · 14 comments
Assignees

Comments

@pourmand1376
Copy link
Collaborator

Slim says that it can minify docker images up to 30x. I should experiment to see if it works well on our docker images.

@george-gca
Copy link
Collaborator

Maybe we could also ditch docker hub and migrate to using GitHub Container registry in the same step? I've seen some other people implementing this like here.

@pourmand1376
Copy link
Collaborator Author

pourmand1376 commented Jul 12, 2023

Maybe we could also ditch docker hub and migrate to using GitHub Container registry in the same step? I've seen some other people implementing this like here.

Does the Github Container registry solves any problem? What does it offer compared to dockerhub?

Currently, Dockerhub compresses our image from 1.3 GB to 500MB. Does it compress the image?

@pourmand1376
Copy link
Collaborator Author

pourmand1376 commented Jul 12, 2023

First you should use docker compose up to pull the image.

Then build an optimized version using:

docker-slim build --compose-file docker-compose.yml --target-compose-svc jekyll

Then, tag the image as slim:

docker image tag amirpourmand/al-folio.slim amirpourmand/al-folio:slim

Image size is reduced to 188 MBs.

@pourmand1376
Copy link
Collaborator Author

@george-gca
Copy link
Collaborator

Oh I didn't know about the compressing feature. I suggested simply because we use GitHub already, so for keeping it all up in one provider. Also Docker did a terrible job communicating changes lately, although they reverted their decisions.

@pourmand1376
Copy link
Collaborator Author

pourmand1376 commented Jul 17, 2023

The slim version is now available at this URL:

docker pull ghcr.io/pourmand1376/al-folio:slim

Test it if you can. You can also change the image name in docker-compose.yml to ghcr.io/pourmand1376/al-folio:slim.
It is very lightweight (188 MB) compared to the standard 500MB.

@pourmand1376
Copy link
Collaborator Author

pourmand1376 commented Jul 19, 2023

You can also use a one-liner to use the slim image:

docker run --rm -v "$PWD:/srv/jekyll/" -p "8080:8080" ghcr.io/pourmand1376/al-folio:slim

@george-gca
Copy link
Collaborator

george-gca commented Jul 25, 2023

Currently throwing an error @pourmand1376:

Dependency Error: Yikes! It looks like you don't have jekyll-get-json or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. If you've run Jekyll with bundle exec, ensure that you have included the jekyll-get-json gem in your Gemfile as well. The full error message from Ruby is: 'cannot load such file -- jekyll-get-json' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!

@pourmand1376
Copy link
Collaborator Author

Let's dig it. It is far more problematic than I thought.

Just, let this be open for a month or two. Perhaps, someone expert on docker does something. Otherwise, 400MB is not that much and it is okay for now.

@george-gca
Copy link
Collaborator

Maybe the only thing missing here is an updated docker image. The jekyll-get-json dependency it is complaining about was recently introduced in #1547. Can you try to generate a newer version so I can check if it works? Or how can I try to create one myself? Is it just the steps you posted here?

First you should use docker compose up to pull the image.

Then build an optimized version using:

docker-slim build --compose-file docker-compose.yml --target-compose-svc jekyll

Then, tag the image as slim:

docker image tag amirpourmand/al-folio.slim amirpourmand/al-folio:slim

Image size is reduced to 188 MBs.

@pourmand1376
Copy link
Collaborator Author

Maybe the only thing missing here is an updated docker image. The jekyll-get-json dependency it is complaining about was recently introduced in #1547. Can you try to generate a newer version so I can check if it works? Or how can I try to create one myself? Is it just the steps you posted here?

First you should use docker compose up to pull the image.
Then build an optimized version using:

docker-slim build --compose-file docker-compose.yml --target-compose-svc jekyll

Then, tag the image as slim:

docker image tag amirpourmand/al-folio.slim amirpourmand/al-folio:slim

Image size is reduced to 188 MBs.

That's true. Most probably there is an issue with a dependency or something. However, It can not be updated manually.

It should be updated automatically. As far as I know, there isn't any automatic way of using docker-slim.

@pourmand1376
Copy link
Collaborator Author

pourmand1376 commented Sep 3, 2023

I have implemented docker-slim on github actions. However, it is not working very good (no error).

@george-gca
Copy link
Collaborator

Can we close this issue @pourmand1376?

@pourmand1376
Copy link
Collaborator Author

Yes. This is finished.

One thing is still left to answer. When should we make this slim version the default version? As I see, It is basically the same but less in size. However, there may be some unpredicted issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants