mirror of https://github.com/docker/docker-py.git
Merge acc26364cc
into 526a9db743
This commit is contained in:
commit
ccfa6b0d6d
|
@ -150,6 +150,19 @@ class ContainerError(DockerException):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ContainerStartError(DockerException):
|
||||||
|
"""
|
||||||
|
Represents a container that has failed to start.
|
||||||
|
"""
|
||||||
|
def __init__(self, container, reason):
|
||||||
|
self.container = container
|
||||||
|
self.msg = reason
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
f"Container '{container.short_id}' failed to start: {reason}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class StreamParseError(RuntimeError):
|
class StreamParseError(RuntimeError):
|
||||||
def __init__(self, reason):
|
def __init__(self, reason):
|
||||||
self.msg = reason
|
self.msg = reason
|
||||||
|
|
|
@ -5,7 +5,9 @@ from collections import namedtuple
|
||||||
from ..api import APIClient
|
from ..api import APIClient
|
||||||
from ..constants import DEFAULT_DATA_CHUNK_SIZE
|
from ..constants import DEFAULT_DATA_CHUNK_SIZE
|
||||||
from ..errors import (
|
from ..errors import (
|
||||||
|
APIError,
|
||||||
ContainerError,
|
ContainerError,
|
||||||
|
ContainerStartError,
|
||||||
DockerException,
|
DockerException,
|
||||||
ImageNotFound,
|
ImageNotFound,
|
||||||
NotFound,
|
NotFound,
|
||||||
|
@ -843,6 +845,8 @@ class ContainerCollection(Collection):
|
||||||
:py:class:`docker.errors.ContainerError`
|
:py:class:`docker.errors.ContainerError`
|
||||||
If the container exits with a non-zero exit code and
|
If the container exits with a non-zero exit code and
|
||||||
``detach`` is ``False``.
|
``detach`` is ``False``.
|
||||||
|
:py:class:`docker.errors.ContainerStartError`
|
||||||
|
If the container fails to start.
|
||||||
:py:class:`docker.errors.ImageNotFound`
|
:py:class:`docker.errors.ImageNotFound`
|
||||||
If the specified image does not exist.
|
If the specified image does not exist.
|
||||||
:py:class:`docker.errors.APIError`
|
:py:class:`docker.errors.APIError`
|
||||||
|
@ -881,7 +885,17 @@ class ContainerCollection(Collection):
|
||||||
container = self.create(image=image, command=command,
|
container = self.create(image=image, command=command,
|
||||||
detach=detach, **kwargs)
|
detach=detach, **kwargs)
|
||||||
|
|
||||||
container.start()
|
try:
|
||||||
|
container.start()
|
||||||
|
except APIError as e:
|
||||||
|
if remove:
|
||||||
|
container.remove()
|
||||||
|
|
||||||
|
if e.explanation:
|
||||||
|
error = e.explanation
|
||||||
|
else:
|
||||||
|
error = e
|
||||||
|
raise ContainerStartError(container, error) from e
|
||||||
|
|
||||||
if detach:
|
if detach:
|
||||||
return container
|
return container
|
||||||
|
|
|
@ -157,13 +157,13 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
with pytest.raises(docker.errors.APIError):
|
with pytest.raises(docker.errors.ContainerStartError) as err:
|
||||||
container = client.containers.run(
|
client.containers.run(
|
||||||
'alpine', 'echo hello world', network=net_name,
|
'alpine', 'echo hello world', network=net_name,
|
||||||
networking_config=networking_config,
|
networking_config=networking_config,
|
||||||
detach=True
|
detach=True
|
||||||
)
|
)
|
||||||
self.tmp_containers.append(container.id)
|
self.tmp_containers.append(err.container.id)
|
||||||
|
|
||||||
def test_run_with_networking_config_only_undeclared_network(self):
|
def test_run_with_networking_config_only_undeclared_network(self):
|
||||||
net_name = random_name()
|
net_name = random_name()
|
||||||
|
|
Loading…
Reference in New Issue