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

[DRAFT][Dockerfile] Leverage caching #42

Open
yelghali opened this issue Apr 6, 2023 · 0 comments
Open

[DRAFT][Dockerfile] Leverage caching #42

yelghali opened this issue Apr 6, 2023 · 0 comments

Comments

@yelghali
Copy link

yelghali commented Apr 6, 2023

Often, the same image has to be rebuilt again & again with slight modifications in code.

Docker helps in such cases by storing the cache of each layer of a build.

Due to this concept, it’s recommended to add the lines which are used for installing dependencies & packages earlier inside the Dockerfile – before the COPY commands.

The reason behind this is that docker would be able to cache the image with the required dependencies, and this cache can then be used in the following builds when code gets modified

bad example
FROM ubuntu:latest
COPY . .
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install vim -y
RUN apt-get install net-tools -y
RUN apt-get install dnsutils -y

good example
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install vim -y
RUN apt-get install net-tools -y
RUN apt-get install dnsutils -y
COPY . .

To help you make your container smallers and more optimized, you can use tools like: https://github.com/slimtoolkit/slim

@yelghali yelghali changed the title [DRAFT][Dockerfile]leverage caching [DRAFT][Dockerfile] Leverage caching Apr 6, 2023
@jhertout jhertout transferred this issue from green-code-initiative/creedengo-challenge May 21, 2024
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