原装容器
$ docker inspect zealous_wozniak --format "{{ json .Mounts }}" | python -m json.tool
[
{
"Destination": "/etc/mast",
"Driver": "local",
"Mode": "",
"Name": "31c0787ccded0a49e1f97e272ac5e37f2a505620b861c13318ff3a49eaef8f16",
"Propagation": "",
"RW": true,
"Source": "/var/lib/docker/volumes/31c0787ccded0a49e1f97e272ac5e37f2a505620b861c13318ff3a49eaef8f16/_data",
"Type": "volume"
},
{
"Destination": "/home/mast/.ssh",
"Driver": "local",
"Mode": "",
"Name": "faaae04539b8ef338a9f6ffecc3098e79d8035d23b07065e8d86fe31bee043fa",
"Propagation": "",
"RW": true,
"Source": "/var/lib/docker/volumes/faaae04539b8ef338a9f6ffecc3098e79d8035d23b07065e8d86fe31bee043fa/_data",
"Type": "volume"
}
]
升级容器
$ docker inspect confident_austin --format "{{ json .Mounts }}" | python -m json.tool
[
{
"Destination": "/etc/mast",
"Driver": "local",
"Mode": "",
"Name": "b053289f632bef2ebddc1a8d1fa8b25c76cb30d2bc990211995faa191b63030b",
"Propagation": "",
"RW": true,
"Source": "/var/lib/docker/volumes/b053289f632bef2ebddc1a8d1fa8b25c76cb30d2bc990211995faa191b63030b/_data",
"Type": "volume"
},
{
"Destination": "/home/mast/.ssh",
"Driver": "local",
"Mode": "",
"Name": "c1438df0435c5c37d202337c7cdf142710d256852b26691fafc90e48818bee15",
"Propagation": "",
"RW": true,
"Source": "/var/lib/docker/volumes/c1438df0435c5c37d202337c7cdf142710d256852b26691fafc90e48818bee15/_data",
"Type": "volume"
},
{
"Destination": "/var/lib/docker/volumes/faaae04539b8ef338a9f6ffecc3098e79d8035d23b07065e8d86fe31bee043fa/_data",
"Driver": "local",
"Mode": "",
"Name": "8d0c7c9e89c82f6c9e68a115aef1605362ed08844bc61459e10183c7f56f7c44",
"Propagation": "",
"RW": true,
"Source": "/var/lib/docker/volumes/8d0c7c9e89c82f6c9e68a115aef1605362ed08844bc61459e10183c7f56f7c44/_data",
"Type": "volume"
},
{
"Destination": "/var/lib/docker/volumes/31c0787ccded0a49e1f97e272ac5e37f2a505620b861c13318ff3a49eaef8f16/_data",
"Driver": "local",
"Mode": "",
"Name": "58d7afdf56b64d0a8301366fe5442620571584104297cc1753b97a3d159a0603",
"Propagation": "",
"RW": true,
"Source": "/var/lib/docker/volumes/58d7afdf56b64d0a8301366fe5442620571584104297cc1753b97a3d159a0603/_data",
"Type": "volume"
}
]
代码
def upgrade_daemon_container(container_id):
old_container_data = docker_api.inspect_container(container_id)
creation_data = get_upgrade_data(old_container_data)
new_container = docker_api.create_container(
image=creation_data.get('image'),
hostname=creation_data.get('hostname'),
volumes=creation_data.get('volumes'),
host_config=docker_api.create_host_config(
binds=creation_data.get('volume_bindings'),
port_bindings={80: 80},
restart_policy={"MaximumRetryCount": 0, "Name": "always"}
))
return new_container
哪里creation_data
看起来像:
{
'hostname': 'defb4b2697bc',
'image': 'docker.akema.fr:5000/coaxis/coaxisopt_daemon:latest',
'networking_config': {
'EndpointsConfig': {
'opt_network_aae2d4': {
'IPAMConfig': {
'IPv4Address': '10.49.0.2'
}
}
}
},
'volumes': [
'/var/lib/docker/volumes/31c0787ccded0a49e1f97e272ac5e37f2a505620b861c13318ff3a49eaef8f16/_data',
'/var/lib/docker/volumes/faaae04539b8ef338a9f6ffecc3098e79d8035d23b07065e8d86fe31bee043fa/_data'
],
'volumes_bindings': {
'/var/lib/docker/volumes/31c0787ccded0a49e1f97e272ac5e37f2a505620b861c13318ff3a49eaef8f16/_data': {
'bind': '/etc/mast',
'mode': 'rw'
},
'/var/lib/docker/volumes/faaae04539b8ef338a9f6ffecc3098e79d8035d23b07065e8d86fe31bee043fa/_data': {
'bind': '/home/mast/.ssh',
'mode': 'rw'
}
}
}
问题
- 为什么我有 4 卷而不是 2 卷?
- 为什么旧卷
Sources
用作Destination
?