I'm working to implement a mechanism to upgrade the base image of a container. In order to do so I need to:
- get the list of volumes from the current container ;
- create a new container with configuration from the old container (volume, network, etc.)
Create new container
I tried to do it like:
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"}
))
Creation data
where creation_data
are gathered from the old container and look like:
{
'image': 'docker.akema.fr:5000/coaxis/coaxisopt_daemon:latest',
'hostname': "test-01",
'volumes': [
"/home/mast/.ssh",
"/etc/mast"
],
'volumes_bindings': {
"841d6a1709b365763c85fb4b7400c87f264d468eb1691a660fe81761da6e374f": {
'bind': "/home/mast/.ssh",
'mode': 'rw'
},
"002730cbb4dd9b37ad808915a60081508885d533fe003b529b8d0ab4fa46e92e": {
'bind': "/etc/mast",
'mode': 'rw'
}
},
'networking_config': {
'EndpointsConfig': {'opt_network_508be7': {'IPAMConfig': {'IPv4Address': '10.0.0.1'}}}
}
}
Question
When inspecting the new container the Mounts
section doesn't seems to have the correct volume, Source
fields is a different path.
How do I mount a volume to a new container based on the old container information?