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
e6af420a
Kaydet (Commit)
e6af420a
authored
Agu 28, 2014
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #304 from shreyu86/dev-restart-policy
Restart Policy for Containers Implemented fixes #302
üst
c76fd8d9
7479d4cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
11 deletions
+81
-11
README.md
README.md
+22
-1
client.py
docker/client.py
+5
-2
integration_test.py
tests/integration_test.py
+17
-0
test.py
tests/test.py
+37
-8
No files found.
README.md
Dosyayı görüntüle @
e6af420a
...
...
@@ -232,7 +232,7 @@ Identical to the `docker search` command.
```
python
c
.
start
(
container
,
binds
=
None
,
port_bindings
=
None
,
lxc_conf
=
None
,
publish_all_ports
=
False
,
links
=
None
,
privileged
=
False
,
dns
=
None
,
dns_search
=
None
,
volumes_from
=
None
,
network_mode
=
None
)
dns
=
None
,
dns_search
=
None
,
volumes_from
=
None
,
network_mode
=
None
,
restart_policy
=
None
)
```
Similar to the
`docker start`
command, but doesn't support attach
...
...
@@ -258,6 +258,27 @@ docker bridge, 'none': no networking for this container, 'container:[name|id]':
reuses another container network stack), 'host': use the host network stack
inside the container.
`restart_policy`
is available since v1.2.0 and sets the RestartPolicy for how a container should or should not be
restarted on exit. By default the policy is set to no meaning do not restart the container when it exits.
The user may specify the restart policy as a dictionary for example:
for example:
```
{
"MaximumRetryCount": 0,
"Name": "always"
}
```
for always restarting the container on exit or can specify to restart the container to restart on failure and can limit
number of restarts.
for example:
```
{
"MaximumRetryCount": 5,
"Name": "on-failure"
}
```
```
python
c
.
stop
(
container
,
timeout
=
10
)
```
...
...
docker/client.py
Dosyayı görüntüle @
e6af420a
...
...
@@ -806,7 +806,8 @@ class Client(requests.Session):
def
start
(
self
,
container
,
binds
=
None
,
port_bindings
=
None
,
lxc_conf
=
None
,
publish_all_ports
=
False
,
links
=
None
,
privileged
=
False
,
dns
=
None
,
dns_search
=
None
,
volumes_from
=
None
,
network_mode
=
None
):
dns
=
None
,
dns_search
=
None
,
volumes_from
=
None
,
network_mode
=
None
,
restart_policy
=
None
):
if
isinstance
(
container
,
dict
):
container
=
container
.
get
(
'Id'
)
...
...
@@ -859,13 +860,15 @@ class Client(requests.Session):
if
volumes_from
is
not
None
:
warnings
.
warn
(
warning_message
.
format
(
'volumes_from'
),
DeprecationWarning
)
if
dns_search
:
start_config
[
'DnsSearch'
]
=
dns_search
if
network_mode
:
start_config
[
'NetworkMode'
]
=
network_mode
if
restart_policy
:
start_config
[
'RestartPolicy'
]
=
restart_policy
url
=
self
.
_url
(
"/containers/{0}/start"
.
format
(
container
))
res
=
self
.
_post_json
(
url
,
data
=
start_config
)
self
.
_raise_for_status
(
res
)
...
...
tests/integration_test.py
Dosyayı görüntüle @
e6af420a
...
...
@@ -612,6 +612,23 @@ class TestStartContainerWithLinks(BaseTestCase):
self
.
assertIn
(
'{0}_NAME='
.
format
(
link_env_prefix2
),
logs
)
self
.
assertIn
(
'{0}_ENV_FOO=1'
.
format
(
link_env_prefix2
),
logs
)
class
TestRestartingContainer
(
BaseTestCase
):
def
runTest
(
self
):
container
=
self
.
client
.
create_container
(
'busybox'
,
[
'false'
])
id
=
container
[
'Id'
]
self
.
client
.
start
(
id
,
restart_policy
=
{
{
"Name"
:
"on-failure"
,
"MaximumRetryCount"
:
1
}
})
self
.
client
.
wait
(
id
)
self
.
client
.
remove_container
(
id
)
containers
=
self
.
client
.
containers
(
all
=
True
)
res
=
[
x
for
x
in
containers
if
'Id'
in
x
and
x
[
'Id'
]
.
startswith
(
id
)]
self
.
assertEqual
(
len
(
res
),
0
)
#################
# LINKS TESTS #
#################
...
...
tests/test.py
Dosyayı görüntüle @
e6af420a
# Copyright 2013 dotCloud inc.
#
Licensed under the Apache License, Version 2.0 (the "License");
#
you may not use this file except in compliance with the License.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
...
...
@@ -60,6 +60,7 @@ def fake_resp(url, data=None, **kwargs):
status_code
,
content
=
fake_api
.
fake_responses
[
url
]()
return
response
(
status_code
=
status_code
,
content
=
content
)
fake_request
=
mock
.
Mock
(
side_effect
=
fake_resp
)
url_prefix
=
'http+unix://var/run/docker.sock/v{0}/'
.
format
(
docker
.
client
.
DEFAULT_DOCKER_API_VERSION
)
...
...
@@ -616,7 +617,7 @@ class DockerClientTest(Cleanup, unittest.TestCase):
mount_origin
=
'/tmp'
self
.
client
.
start
(
fake_api
.
FAKE_CONTAINER_ID
,
binds
=
{
mount_origin
:
{
"bind"
:
mount_dest
,
"ro"
:
False
}})
"bind"
:
mount_dest
,
"ro"
:
False
}})
except
Exception
as
e
:
self
.
fail
(
'Command should not raise exception: {0}'
.
format
(
e
))
...
...
@@ -812,6 +813,34 @@ class DockerClientTest(Cleanup, unittest.TestCase):
docker
.
client
.
DEFAULT_TIMEOUT_SECONDS
)
def
test_start_container_with_restart_policy
(
self
):
try
:
self
.
client
.
start
(
fake_api
.
FAKE_CONTAINER_ID
,
restart_policy
=
{
"Name"
:
"always"
,
"MaximumRetryCount"
:
0
})
except
Exception
as
e
:
self
.
fail
(
'Command should not raise exception: {0}'
.
format
(
e
))
args
=
fake_request
.
call_args
self
.
assertEqual
(
args
[
0
][
0
],
url_prefix
+
'containers/3cc2351ab11b/start'
)
self
.
assertEqual
(
json
.
loads
(
args
[
1
][
'data'
]),
{
"PublishAllPorts"
:
False
,
"Privileged"
:
False
,
"RestartPolicy"
:
{
"MaximumRetryCount"
:
0
,
"Name"
:
"always"
}}
)
self
.
assertEqual
(
args
[
1
][
'headers'
],
{
'Content-Type'
:
'application/json'
}
)
self
.
assertEqual
(
args
[
1
][
'timeout'
],
docker
.
client
.
DEFAULT_TIMEOUT_SECONDS
)
def
test_resize_container
(
self
):
try
:
self
.
client
.
resize
(
...
...
@@ -1536,11 +1565,11 @@ class DockerClientTest(Cleanup, unittest.TestCase):
f
.
write
(
"content"
)
for
exclude
,
names
in
(
([
'*.py'
],
[
'bar/a.txt'
,
'bar/other.png'
,
'test/foo/a.txt'
,
'test/foo/other.png'
]),
([
'*.png'
,
'bar'
],
[
'test/foo/a.txt'
,
'test/foo/b.py'
]),
([
'test/foo'
,
'a.txt'
],
[
'bar/a.txt'
,
'bar/b.py'
,
'bar/other.png'
]),
([
'*.py'
],
[
'bar/a.txt'
,
'bar/other.png'
,
'test/foo/a.txt'
,
'test/foo/other.png'
]),
([
'*.png'
,
'bar'
],
[
'test/foo/a.txt'
,
'test/foo/b.py'
]),
([
'test/foo'
,
'a.txt'
],
[
'bar/a.txt'
,
'bar/b.py'
,
'bar/other.png'
]),
):
archive
=
docker
.
utils
.
tar
(
base
,
exclude
=
exclude
)
tar
=
tarfile
.
open
(
fileobj
=
archive
)
...
...
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