Improve Dockerfile: Remove unnecessary docker binary duplication#4480
Open
arturmartins wants to merge 6 commits into
Open
Improve Dockerfile: Remove unnecessary docker binary duplication#4480arturmartins wants to merge 6 commits into
arturmartins wants to merge 6 commits into
Conversation
Moving the docker binaries into the build layer and copy it directly to the expected path.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Docker image build to stage Docker CLI binaries into a dedicated directory during the build phase and then copy them into the final image, simplifying the final-stage installation steps.
Changes:
- Install extracted Docker binaries into
/docker-binin the build stage and remove the extracteddocker/directory. - Replace the final-stage
RUN install ...step with aCOPY --from=build /docker-bin/ /usr/bin/. - Keep
docker-buildxplugin copied into/usr/local/lib/docker/cli-plugins/in the final stage.
Comment on lines
+34
to
+36
| && mkdir -p /docker-bin \ | ||
| && install -o root -g root -m 755 docker/* /docker-bin/ \ | ||
| && rm -rf docker \ |
Author
There was a problem hiding this comment.
I'm just following the same process as before, but I would rather use chmod/chown. Happy to do that, if reviewers require it.
|
|
||
| COPY --chown=runner:docker --from=build /actions-runner . | ||
| COPY --from=build /usr/local/lib/docker/cli-plugins/docker-buildx /usr/local/lib/docker/cli-plugins/docker-buildx | ||
| COPY --from=build /docker-bin/ /usr/bin/ |
Comment on lines
+34
to
+36
| && mkdir -p /docker-bin \ | ||
| && install -o root -g root -m 755 docker/* /docker-bin/ \ | ||
| && rm -rf docker \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR:
Shrink the total image size by moving the docker binaries into the build layer and copy them directly to the expected path.
Problem:
8th Layer: (934MB)
In this layer, the COPY command copies everything from
/actions-runnerinto/home/runnerwhich includes/home/runner/docker.10th Layer: (235 MB)
In a later stage, the RUN executes the
installcommand which moves the files from/hom/runner/docker/*to/usr/binand sets up gid/uid and file permissions for each file.Proposed solution:
Moving the logic into the build stage into a separate path
/docker-bin/ and copying after it straight to/usr/bin`, decreasing the layer size from 934MB to 699MB (25% reduction).The copy of the Docker binaries: