Can You Build a Docker Image Without Pulling the Base Image?

0
5
Asked By CuriousCoder92 On

I was wondering if it's possible to build and push a Docker image without the need to pull the base image first. Normally, a `Dockerfile` that includes a `FROM` directive pulls the specified image during the build process. I've used the `COPY --link --from=` feature to copy content from another image, which also pulls that image at build time. However, I'm curious if there's a way to avoid pulling a massive base image every time when all I really want to do is add a few changes. For instance, if I have a Dockerfile like this: `FROM some-massive-base-image` and then `COPY ./my-app /usr/local/bin/my-app`, is it possible to build it without that base image getting downloaded? I know that when using Docker Buildx, it still pulls images for linked layers even if those layers aren't counted towards the final image size. It seems like some tooling could help speed up the process, especially when working with large images required for CUDA projects. Could I work around this behavior, assuming the new layers I'm adding don't depend on the parent layers?

1 Answer

Answered By TechSavvy41 On

Yeah, Docker and OCI are smart enough to handle layer optimization, but you still need the entire base image for building, unfortunately. To mitigate the issue you're facing, I recommend using multi-stage builds where possible. This way, you can minimize the base image size you're dealing with during your builds. Once you have the base image locally, Docker will use its layers on subsequent builds without pulling it again. So even though you need the base image first, it won't continuously download the same layers after that. Have you checked out the multi-stage build documentation on Docker's site? It might come in handy for your scenario.

CuriousCoder92 -

I appreciate the suggestion! I'm familiar with multi-stage builds, but my question specifically concerns avoiding large base images at all during the build process. Typically those heavy images like CUDA runtime can take up quite a bit of space. I'm really looking for any methods to only push the additional layers I need.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.