Skip to content

Commit

Permalink
Fix #295: allow passing credentials into run() call to pulling absent…
Browse files Browse the repository at this point in the history
… image from a private registry (#606)
  • Loading branch information
asvetlov committed Jul 21, 2021
1 parent 50421c4 commit 2ad735b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/295.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Accept auth parameter by `run()` method; it allows auto-pulling absent image from private storages.
15 changes: 12 additions & 3 deletions aiodocker/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,28 @@ async def create(self, config, *, name=None):
)
return DockerContainer(self.docker, id=data["Id"])

async def run(self, config, *, name=None):
async def run(
self,
config,
*,
name: Optional[str] = None,
auth: Optional[Union[Mapping, str, bytes]] = None,
):
"""
Create and start a container.
If container.start() will raise an error the exception will contain
a `container_id` attribute with the id of the container.
Use `auth` for specifying credentials for pulling absent image from
a private registry.
"""
try:
container = await self.create(config, name=name)
except DockerError as err:
# image not find, try pull it
# image not fount, try pulling it
if err.status == 404 and "Image" in config:
await self.docker.pull(config["Image"])
await self.docker.pull(config["Image"], auth=auth)
container = await self.create(config, name=name)
else:
raise err
Expand Down

0 comments on commit 2ad735b

Please sign in to comment.