Skip to content

Bug: Docker image build kwargs is not working #706

Closed

Description

@Tranquility2

Describe the bug

When using kwargs in the Image API, the params are not passed into the build

To Reproduce

For example:

with DockerImage(path="./", tag="new:test", buildargs={"PIP_EXTRA_INDEX_URL": PIP_EXTRA_INDEX_URL}) as image:

The PIP_EXTRA_INDEX_URL fails to register in the docker image build process:

E               docker.errors.BuildError: The command '/bin/sh -c pip3 install --no-cache-dir -r requirements.txt --extra-index-url ${PIP_EXTRA_INDEX_URL}' returned a non-zero code: 2

Activity

  1. Tranquility2 commented on Oct 1, 2024

    @Tranquility2
    ContributorAuthor
    class DockerImage:
    ...
        def __init__(
            self,
            path: Union[str, PathLike],
            docker_client_kw: Optional[dict] = None,
            tag: Optional[str] = None,
            clean_up: bool = True,
            dockerfile_path: Union[str, PathLike] = "Dockerfile",
            no_cache: bool = False,
            **kwargs,
        ) -> None:
    ...
        def build(self, **kwargs) -> Self:
            logger.info(f"Building image from {self.path}")
            docker_client = self.get_docker_client()
            self._image, self._logs = docker_client.build(
                path=str(self.path), tag=self.tag, dockerfile=self._dockerfile_path, nocache=self._no_cache, **kwargs
            )
            logger.info(f"Built image {self.short_id} with tag {self.tag}")
            return self
    ...
        def __enter__(self) -> Self:
            return self.build()

    As can be seen kwargs is not passed/used correctly...
    This is ofc my bad, sorry.
    Will create a fix asap.

    maybe also take the time to add something like #614

  2. Tranquility2 commented on Oct 1, 2024

    @Tranquility2
    ContributorAuthor

    Workaround

    Just use the lower level methods

    def test_something():
        image = DockerImage(path="./", tag="new:test")
        image.build(buildargs={"PIP_EXTRA_INDEX_URL": PIP_EXTRA_INDEX_URL})
        with AWSLambdaContainer(image=image, port=8080) as func:
           # Do Something with the container
        image.remove()
  3. black-snow commented on Oct 1, 2024

    @black-snow
    Contributor

    I feel like this was my original issue with build args exactly :D

  4. added a commit that references this issue on Apr 4, 2025
    cc02f94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions