Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
6b8dfe42
Kaydet (Commit)
6b8dfe42
authored
Ara 14, 2017
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Retrieve container logs before container exits / is removed
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
8cfd4cb3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
18 deletions
+43
-18
containers.py
docker/models/containers.py
+19
-10
models_containers_test.py
tests/integration/models_containers_test.py
+20
-3
fake_api_client.py
tests/unit/fake_api_client.py
+1
-1
models_containers_test.py
tests/unit/models_containers_test.py
+3
-4
No files found.
docker/models/containers.py
Dosyayı görüntüle @
6b8dfe42
...
...
@@ -629,6 +629,9 @@ class ContainerCollection(Collection):
(e.g. ``SIGINT``).
storage_opt (dict): Storage driver options per container as a
key-value mapping.
stream (bool): If true and ``detach`` is false, return a log
generator instead of a string. Ignored if ``detach`` is true.
Default: ``False``.
sysctls (dict): Kernel parameters to set in the container.
tmpfs (dict): Temporary filesystems to mount, as a dictionary
mapping a path inside the container to options for that path.
...
...
@@ -696,6 +699,7 @@ class ContainerCollection(Collection):
"""
if
isinstance
(
image
,
Image
):
image
=
image
.
id
stream
=
kwargs
.
pop
(
'stream'
,
False
)
detach
=
kwargs
.
pop
(
"detach"
,
False
)
if
detach
and
remove
:
if
version_gte
(
self
.
client
.
api
.
_version
,
'1.25'
):
...
...
@@ -723,23 +727,28 @@ class ContainerCollection(Collection):
if
detach
:
return
container
exit_status
=
container
.
wait
()
if
exit_status
!=
0
:
stdout
=
False
stderr
=
True
logging_driver
=
container
.
attrs
[
'HostConfig'
][
'LogConfig'
][
'Type'
]
out
=
None
if
logging_driver
==
'json-file'
or
logging_driver
==
'journald'
:
out
=
container
.
logs
(
stdout
=
stdout
,
stderr
=
stderr
)
else
:
out
=
None
out
=
container
.
logs
(
stdout
=
stdout
,
stderr
=
stderr
,
stream
=
True
,
follow
=
True
)
exit_status
=
container
.
wait
()
if
exit_status
!=
0
:
out
=
container
.
logs
(
stdout
=
False
,
stderr
=
True
)
if
remove
:
container
.
remove
()
if
exit_status
!=
0
:
raise
ContainerError
(
container
,
exit_status
,
command
,
image
,
out
)
return
out
raise
ContainerError
(
container
,
exit_status
,
command
,
image
,
out
)
return
out
if
stream
or
out
is
None
else
b
''
.
join
(
[
line
for
line
in
out
]
)
def
create
(
self
,
image
,
command
=
None
,
**
kwargs
):
"""
...
...
tests/integration/models_containers_test.py
Dosyayı görüntüle @
6b8dfe42
import
docker
import
tempfile
from
.base
import
BaseIntegrationTest
,
TEST_API_VERSION
from
..helpers
import
random_name
from
..helpers
import
random_name
,
requires_api_version
class
ContainerCollectionTest
(
BaseIntegrationTest
):
...
...
@@ -95,7 +95,7 @@ class ContainerCollectionTest(BaseIntegrationTest):
"alpine"
,
"echo hello"
,
log_config
=
dict
(
type
=
'none'
)
)
self
.
assertEqual
(
out
,
None
)
assert
out
is
None
def
test_run_with_json_file_driver
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
...
...
@@ -104,7 +104,24 @@ class ContainerCollectionTest(BaseIntegrationTest):
"alpine"
,
"echo hello"
,
log_config
=
dict
(
type
=
'json-file'
)
)
self
.
assertEqual
(
out
,
b
'hello
\n
'
)
assert
out
==
b
'hello
\n
'
@requires_api_version
(
'1.25'
)
def
test_run_with_auto_remove
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
out
=
client
.
containers
.
run
(
'alpine'
,
'echo hello'
,
auto_remove
=
True
)
assert
out
==
b
'hello
\n
'
def
test_run_with_streamed_logs
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
out
=
client
.
containers
.
run
(
'alpine'
,
'sh -c "echo hello && echo world"'
,
stream
=
True
)
logs
=
[
line
for
line
in
out
]
assert
logs
[
0
]
==
b
'hello
\n
'
assert
logs
[
1
]
==
b
'world
\n
'
def
test_get
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
...
...
tests/unit/fake_api_client.py
Dosyayı görüntüle @
6b8dfe42
...
...
@@ -43,7 +43,7 @@ def make_fake_api_client():
fake_api
.
get_fake_inspect_container
()[
1
],
'inspect_image.return_value'
:
fake_api
.
get_fake_inspect_image
()[
1
],
'inspect_network.return_value'
:
fake_api
.
get_fake_network
()[
1
],
'logs.return_value'
:
'hello world
\n
'
,
'logs.return_value'
:
[
b
'hello world
\n
'
]
,
'networks.return_value'
:
fake_api
.
get_fake_network_list
()[
1
],
'start.return_value'
:
None
,
'wait.return_value'
:
0
,
...
...
tests/unit/models_containers_test.py
Dosyayı görüntüle @
6b8dfe42
...
...
@@ -12,7 +12,7 @@ class ContainerCollectionTest(unittest.TestCase):
client
=
make_fake_client
()
out
=
client
.
containers
.
run
(
"alpine"
,
"echo hello world"
)
assert
out
==
'hello world
\n
'
assert
out
==
b
'hello world
\n
'
client
.
api
.
create_container
.
assert_called_with
(
image
=
"alpine"
,
...
...
@@ -24,9 +24,8 @@ class ContainerCollectionTest(unittest.TestCase):
client
.
api
.
start
.
assert_called_with
(
FAKE_CONTAINER_ID
)
client
.
api
.
wait
.
assert_called_with
(
FAKE_CONTAINER_ID
)
client
.
api
.
logs
.
assert_called_with
(
FAKE_CONTAINER_ID
,
stderr
=
False
,
stdout
=
True
FAKE_CONTAINER_ID
,
stderr
=
False
,
stdout
=
True
,
stream
=
True
,
follow
=
True
)
def
test_create_container_args
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment