docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

passing buildargs to client.build() doesnt work

Open mhshami01 opened this issue 3 years ago • 1 comments

using a Dockerfile similar to the following:

ARG BASE_IMAGE="3.6" FROM amd64/python:${BASE_IMAGE}-slim-buster WORKDIR /app COPY requirements.txt ./ RUN pip install -r requirements.txt COPY . . CMD [ "python3", "-u", "./main.py" ]

When using docker client.build() and passing {'BASE_IMAGE': '3.8'} for buildargs is not working. The image generated is using BASE_IMAGE value 3.6. My expectation is that it would work same as though docker build cli command was used.

mhshami01 avatar Mar 01 '22 19:03 mhshami01

I've got a similar problem. Python SDK 7.1.0 running on a Debian 11 device.

Here's my Dockerfile.

FROM node:18.20.4-bookworm

# No default value for this argument
ARG GITHUB_PAT

RUN git clone "https://foo:[email protected]/myorganization/some_repo.git"
RUN cd some_repo && yarn install && yarn build

WORKDIR /some_repo
ENTRYPOINT ["yarn", "start"]
EXPOSE 3000

When I build this Dockerfile from a bash shell, it works perfectly. The argument '$GITHUB_PAT' is successfully substituted with whatever build arguments I pass:

docker build \
  --network=host \
  --build-arg GITHUB_PAT=foo_bar_baz \
  -f Dockerfile .

However, when I used the docker-py library and pass a buildargs dictionary, no substitution happens. Instead the string literal https://foo:[email protected]/myorganization/some_repo.git is passed to GitHub. Which of course fails to authenticate.

I've tried both the standard API (client.images.build), as well as the low-level APIClient: both fail in the same way.

client = docker.from_env()
buildargs = { "GITHUB_PAT": "foo_bar_baz" }
client.images.build(path="path_to_dockerfile", buildargs=buildargs)

brian-pond avatar Aug 02 '24 22:08 brian-pond