docker / docker/docker-py

Build does not persist chmod (SUID/SGID) changes when using Docker SDK, unlike docker build CLI

Open
#3,323 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I encountered an issue when building a Docker image using the Python Docker SDK. The behavior occurs only with a specific base image so far: gradle:7.6-jdk17-alpine.

In my Dockerfile, I include the following command in a RUN instruction to find and remove files with SUID/SGID permissions:

  • RUN find / -type d -name proc -prune -o -perm /u=s,g=s -exec chmod -s ‘{}’ ;

This step executes successfully during the build (as confirmed in the build logs), but the permission changes do not persist in the resulting image when using the Docker SDK.

However, when I build the exact same Dockerfile using the Docker CLI (docker build), the permission changes are correctly applied and persist in the final image.

This discrepancy suggests that the Docker SDK’s APIClient().build() method may not properly track or commit permission-only changes to the layer (e.g., chmod -s). The issue might be related to Docker’s layer diffing or snapshot mechanism, especially for metadata-only changes (like permissions, ownership, or timestamps).

I’ve verified that:

  • The DOCKER_BUILDKIT=1 environment variable is set before using the SDK.
  • The issue is not present in other images I’ve tested — only with gradle:7.6-jdk17-alpine.
    Please confirm if this is a known limitation of the Docker SDK build process, or if there’s a workaround to ensure such changes persist in the final image when built via the SDK.

Thanks in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the discrepancy with the mentioned Dockerfile, gradle:7.6-jdk17-alpine, and APIClient().build(), then compare the resulting permissions with a docker build CLI result. Inspect whether the chmod-only change is represented in the built layer. Done means identifying the cause and providing a reproducible fix, limitation, or workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
build-system, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.