Skip to content

[build] Fix rsync failure in Docker builds when SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled#24604

Merged
kperumalbfn merged 5 commits intosonic-net:masterfrom
DavidZagury:master_rsync_error
Jan 5, 2026
Merged

[build] Fix rsync failure in Docker builds when SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled#24604
kperumalbfn merged 5 commits intosonic-net:masterfrom
DavidZagury:master_rsync_error

Conversation

@DavidZagury
Copy link
Copy Markdown
Contributor

Why I did it

When building SONiC with SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y, Docker multi-stage builds fail during rsync operations with the following error:

rsync: [generator] failed to set times on "/changes-to-image": Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)

This issue occurs specifically when:

  • Using Docker Engine 20.10.x with BuildKit
  • Running builds inside containers (Docker-in-Docker scenario)
  • Accessing the host Docker daemon via socket mount
  • Using --mount=type=bind in multi-stage Dockerfiles

The root cause is that Docker BuildKit creates read-only bind mounts, and rsync with the -a flag (which includes -t for preserving times) attempts to set timestamps on the mounted directory itself, failing on the read-only mount point.

This blocks builds in environments using native dockerd for build acceleration.

Work item tracking
  • Microsoft ADO (number only):

How I did it

Added --omit-dir-times flag to all rsync commands in Dockerfile.j2 templates that use bind mounts for multi-stage builds.

This flag tells rsync to skip setting directory timestamps (not needed for functionality) while still preserving:

  • All file timestamps
  • All file content and permissions
  • All directory structure

The fix is applied to 37 Dockerfile.j2 files:

  • 34 files in dockers/ directory (common base Docker images used by all platforms)
  • 3 files in platform/mellanox/ directory

How to verify it

Build SONiC using SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
Verify Docker images build successfully

Which release branch to backport (provide reason below if selected)

  • 202205
  • 202211
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@DavidZagury DavidZagury requested review from saiarcot895 and removed request for lguohan and qiluo-msft November 23, 2025 21:01
@DavidZagury
Copy link
Copy Markdown
Contributor Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Copy Markdown
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@tirupatihemanth
Copy link
Copy Markdown
Contributor

@saiarcot895 Please help review/approve/merge this change to fix the prod trixie build as well

@DavidZagury
Copy link
Copy Markdown
Contributor Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Copy Markdown
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bingwang-ms
Copy link
Copy Markdown
Contributor

@liushilongbuaa , @saiarcot895 Can you please help review?

@liushilongbuaa
Copy link
Copy Markdown
Contributor

/azpw ms_conflict

Copy link
Copy Markdown
Contributor

@liushilongbuaa liushilongbuaa left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@saiarcot895 saiarcot895 left a comment

Choose a reason for hiding this comment

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

I see Mellanox platform has been updated, what about Broadcom, VS, and Marvell platforms?

@DavidZagury
Copy link
Copy Markdown
Contributor Author

I see Mellanox platform has been updated, what about Broadcom, VS, and Marvell platforms?

@saiarcot895 as we cannot test it for their platform we cannot do that for other vendors.

@volodymyrsamotiy
Copy link
Copy Markdown
Collaborator

@saiarcot895 , could you please approve if no more comments?

@dprital
Copy link
Copy Markdown
Collaborator

dprital commented Dec 11, 2025

@saiarcot895 , could you please approve if no more comments?

@saiarcot895 , can you please ?

@bingwang-ms
Copy link
Copy Markdown
Contributor

@saiarcot895 Can you please review? Thanks

@saiarcot895
Copy link
Copy Markdown
Contributor

VS can absolutely be tested; it's just a VM running on a system with at least 6GB of free RAM and 2 cores that can be spared.

Additionally, because of the specificity of the command, I'd rather not see this diverge between different dockerfiles. This will just mean more maintenance work later when changes need to be made for whatever reason.

@saiarcot895
Copy link
Copy Markdown
Contributor

Actually, one improvement is to make this into a macro in dockerfile-macros.j2 and use that macro in each Dockerfile.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

…RD_FOR_BUILD is enabled

When building with SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y, Docker
multi-stage builds fail during rsync operations with the following error:

  rsync: [generator] failed to set times on "/changes-to-image":
  Read-only file system (30)
  rsync error: some files/attrs were not transferred (code 23)

Root Cause:
When SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled, Docker BuildKit
treats bind mounts as read-only by default. The rsync command with -a flag
(which includes -t for preserving times) attempts to set timestamps on the
mounted directory itself, which fails when the mount is read-only.

Solution:
Add --omit-dir-times flag to rsync commands in Dockerfile.j2 templates to
skip setting directory timestamps on the bind-mounted source directory.
This prevents rsync from attempting to modify the read-only mount while
still preserving all file timestamps and content.

Impact:
- Fixes builds with SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
- No functional impact on default builds
- Updated 37 Dockerfile.j2 templates across dockers/ and platform/

Signed-off-by: david.zagury <[email protected]>
Signed-off-by: david.zagury <[email protected]>
{%- endmacro %}

{% macro rsync_from_builder_stage() -%}
RUN --mount=type=bind,from=base,target=/changes-to-image rsync -axAX --omit-dir-times --no-D --exclude=/sys --exclude=/proc --exclude=/dev --exclude=resolv.conf /changes-to-image/ /
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Have you considered doing it this way:

FROM scratch
COPY --from=base / /

Would that work too?

Copy link
Copy Markdown
Contributor

@saiarcot895 saiarcot895 Feb 9, 2026

Choose a reason for hiding this comment

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

@benoit-nexthop That was my initial approach, but because of differences in kernel settings around overlayfs, this could register as all files being changed even if there are no changes. More details in 0b85785.

@mssonicbld
Copy link
Copy Markdown
Collaborator

Cherry-pick PR to 202511: #25093

jasonbridges pushed a commit to jasonbridges/sonic-buildimage that referenced this pull request Jan 22, 2026
…VE_DOCKERD_FOR_BUILD is enabled (sonic-net#24604)

[build] Fix rsync failure in Docker builds when SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled
DavidZagury added a commit to DavidZagury/sonic-buildimage that referenced this pull request Feb 3, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled

This is the same fix as in sonic-net#24604 to the new otel docker

Signed-off-by: david.zagury <[email protected]>
DavidZagury added a commit to DavidZagury/sonic-buildimage that referenced this pull request Feb 4, 2026
…_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled

This is the same fix as in sonic-net#24604 to the new restapi-sidecar docker

Signed-off-by: david.zagury <[email protected]>
croos12 pushed a commit to croos12/sonic-buildimage that referenced this pull request Feb 6, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled

This is the same fix as in sonic-net#24604 to the new otel docker
croos12 pushed a commit to croos12/sonic-buildimage that referenced this pull request Feb 6, 2026
…_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled

This is the same fix as in sonic-net#24604 to the new restapi-sidecar docker

Signed-off-by: david.zagury <[email protected]>
liat-grozovik pushed a commit that referenced this pull request Feb 18, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled (#25328)

This is the same fix as in #24604 to the new otel docker

- Why I did it
When building SONiC with SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y, Docker multi-stage builds fail during rsync operations with the following error:

rsync: [generator] failed to set times on "/changes-to-image": Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)
This issue occurs specifically when:

Using Docker Engine 20.10.x with BuildKit
Running builds inside containers (Docker-in-Docker scenario)
Accessing the host Docker daemon via socket mount
Using --mount=type=bind in multi-stage Dockerfiles
The root cause is that Docker BuildKit creates read-only bind mounts, and rsync with the -a flag (which includes -t for preserving times) attempts to set timestamps on the mounted directory itself, failing on the read-only mount point.

This blocks builds in environments using native dockerd for build acceleration.

- How I did it
Use the defined in dockerfile-macros.j2 on the otel docker

- How to verify it
Build SONiC using SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
Verify Docker images build successfully

Signed-off-by: david.zagury <[email protected]>
FengPan-Frank pushed a commit to FengPan-Frank/sonic-buildimage that referenced this pull request Mar 6, 2026
…VE_DOCKERD_FOR_BUILD is enabled (sonic-net#24604)

[build] Fix rsync failure in Docker builds when SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled

Signed-off-by: Feng Pan <[email protected]>
FengPan-Frank pushed a commit to FengPan-Frank/sonic-buildimage that referenced this pull request Mar 6, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled (sonic-net#25328)

This is the same fix as in sonic-net#24604 to the new otel docker

- Why I did it
When building SONiC with SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y, Docker multi-stage builds fail during rsync operations with the following error:

rsync: [generator] failed to set times on "/changes-to-image": Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)
This issue occurs specifically when:

Using Docker Engine 20.10.x with BuildKit
Running builds inside containers (Docker-in-Docker scenario)
Accessing the host Docker daemon via socket mount
Using --mount=type=bind in multi-stage Dockerfiles
The root cause is that Docker BuildKit creates read-only bind mounts, and rsync with the -a flag (which includes -t for preserving times) attempts to set timestamps on the mounted directory itself, failing on the read-only mount point.

This blocks builds in environments using native dockerd for build acceleration.

- How I did it
Use the defined in dockerfile-macros.j2 on the otel docker

- How to verify it
Build SONiC using SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
Verify Docker images build successfully

Signed-off-by: david.zagury <[email protected]>
Signed-off-by: Feng Pan <[email protected]>
mssonicbld added a commit to mssonicbld/sonic-buildimage that referenced this pull request Mar 9, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled

This is the same fix as in sonic-net#24604 to the new otel docker

<!--
     Please make sure you've read and understood our contributing guidelines:
     https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

     ** Make sure all your commits include a signature generated with `git commit -s` **

     If this is a bug fix, make sure your description includes "fixes #xxxx", or
     "closes #xxxx" or "resolves #xxxx"

     Please provide the following information:
-->

#### Why I did it
When building SONiC with `SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y`, Docker multi-stage builds fail during rsync operations with the following error:

```
rsync: [generator] failed to set times on "/changes-to-image": Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)
```

This issue occurs specifically when:
- Using Docker Engine 20.10.x with BuildKit
- Running builds inside containers (Docker-in-Docker scenario)
- Accessing the host Docker daemon via socket mount
- Using `--mount=type=bind` in multi-stage Dockerfiles

The root cause is that Docker BuildKit creates read-only bind mounts, and rsync with the `-a` flag (which includes `-t` for preserving times) attempts to set timestamps on the mounted directory itself, failing on the read-only mount point.

This blocks builds in environments using native dockerd for build acceleration.

##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it
Use the defined in dockerfile-macros.j2 on the otel docker

#### How to verify it
Build SONiC using SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
Verify Docker images build successfully

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

Signed-off-by: Sonic Build Admin <[email protected]>

#### A picture of a cute animal (not mandatory but encouraged)
mssonicbld added a commit that referenced this pull request Mar 17, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled (#25982)

This is the same fix as in #24604 to the new otel docker

<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "fixes #xxxx", or
 "closes #xxxx" or "resolves #xxxx"

 Please provide the following information:
-->

#### Why I did it
When building SONiC with `SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y`, Docker multi-stage builds fail during rsync operations with the following error:

```
rsync: [generator] failed to set times on "/changes-to-image": Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)
```

This issue occurs specifically when:
- Using Docker Engine 20.10.x with BuildKit
- Running builds inside containers (Docker-in-Docker scenario)
- Accessing the host Docker daemon via socket mount
- Using `--mount=type=bind` in multi-stage Dockerfiles

The root cause is that Docker BuildKit creates read-only bind mounts, and rsync with the `-a` flag (which includes `-t` for preserving times) attempts to set timestamps on the mounted directory itself, failing on the read-only mount point.

This blocks builds in environments using native dockerd for build acceleration.

##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it
Use the defined in dockerfile-macros.j2 on the otel docker

#### How to verify it
Build SONiC using SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
Verify Docker images build successfully

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

Signed-off-by: Sonic Build Admin <[email protected]>

#### A picture of a cute animal (not mandatory but encouraged)
dprital pushed a commit that referenced this pull request Mar 19, 2026
…VE_DOCKERD_FOR_BUILD is enabled (#24604)

[build] Fix rsync failure in Docker builds when SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD is enabled

Signed-off-by: dprital <[email protected]>
dprital pushed a commit that referenced this pull request Mar 19, 2026
…_NATIVE_DOCKERD_FOR_BUILD is enabled (#25328)

This is the same fix as in #24604 to the new otel docker

- Why I did it
When building SONiC with SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y, Docker multi-stage builds fail during rsync operations with the following error:

rsync: [generator] failed to set times on "/changes-to-image": Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)
This issue occurs specifically when:

Using Docker Engine 20.10.x with BuildKit
Running builds inside containers (Docker-in-Docker scenario)
Accessing the host Docker daemon via socket mount
Using --mount=type=bind in multi-stage Dockerfiles
The root cause is that Docker BuildKit creates read-only bind mounts, and rsync with the -a flag (which includes -t for preserving times) attempts to set timestamps on the mounted directory itself, failing on the read-only mount point.

This blocks builds in environments using native dockerd for build acceleration.

- How I did it
Use the defined in dockerfile-macros.j2 on the otel docker

- How to verify it
Build SONiC using SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
Verify Docker images build successfully

Signed-off-by: david.zagury <[email protected]>
Signed-off-by: dprital <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.