Skip to content

Improve Dockerfile: Remove unnecessary docker binary duplication#4480

Open
arturmartins wants to merge 6 commits into
actions:mainfrom
arturmartins:arturmartins-improve-dockerfile
Open

Improve Dockerfile: Remove unnecessary docker binary duplication#4480
arturmartins wants to merge 6 commits into
actions:mainfrom
arturmartins:arturmartins-improve-dockerfile

Conversation

@arturmartins

@arturmartins arturmartins commented Jun 8, 2026

Copy link
Copy Markdown

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)

COPY --chown=runner:docker /actions-runner . # buildkit
Screenshot 2026-06-08 at 15 11 40

In this layer, the COPY command copies everything from /actions-runner into /home/runner which includes /home/runner/docker.

10th Layer: (235 MB)

RUN /bin/sh -c install -o root -g root -m 755 docker/* /usr/bin/ && rm -rf docker # buildkit

In a later stage, the RUN executes the install command which moves the files from /hom/runner/docker/* to /usr/bin and sets up gid/uid and file permissions for each file.

Screenshot 2026-06-08 at 15 12 13

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).

Screenshot 2026-06-08 at 16 51 40

The copy of the Docker binaries:

Screenshot 2026-06-08 at 16 51 56

@arturmartins arturmartins marked this pull request as ready for review June 8, 2026 15:36
@arturmartins arturmartins requested a review from a team as a code owner June 8, 2026 15:36
Copilot AI review requested due to automatic review settings June 8, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-bin in the build stage and remove the extracted docker/ directory.
  • Replace the final-stage RUN install ... step with a COPY --from=build /docker-bin/ /usr/bin/.
  • Keep docker-buildx plugin copied into /usr/local/lib/docker/cli-plugins/ in the final stage.

@arturmartins arturmartins requested a review from Copilot June 8, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread images/Dockerfile
Comment on lines +34 to +36
&& mkdir -p /docker-bin \
&& install -o root -g root -m 755 docker/* /docker-bin/ \
&& rm -rf docker \

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just following the same process as before, but I would rather use chmod/chown. Happy to do that, if reviewers require it.

Comment thread images/Dockerfile

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/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a comment help?

@arturmartins arturmartins requested a review from Copilot June 8, 2026 19:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread images/Dockerfile
Comment thread images/Dockerfile
Comment on lines +34 to +36
&& mkdir -p /docker-bin \
&& install -o root -g root -m 755 docker/* /docker-bin/ \
&& rm -rf docker \
@arturmartins arturmartins changed the title Improve Dockerfile: Remove unnecessary layer Improve Dockerfile: Remove unnecessary docker binary duplication Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants