How to upgrade docker container with previous netw

2019-09-18 07:51发布

问题:

I'm developing an app where we pop containers with volumes and custom network.

I need to add the feature where admin will be able to upgrade the running container to latest version. So I was hoping to be able to fetch the various information from it the pop a new container with the old config.

Question

However I'm not sure what I really need to grab on the old container and how to use it. For instance,

  • Is NetworkSettings.Networks enough or is there network information elsewhere in the data ?
  • How do I mount a volume with the infos in Mounts?

        {
            "Type": "volume",
            "Name": "841d6a1709b365763c85fb4b7400c87f264d468eb1691a660fe81761da6e374f",
            "Source": "/var/lib/docker/volumes/841d6a1709b365763c85fb4b7400c87f264d468eb1691a660fe81761da6e374f/_data",
            "Destination": "/home/mast/.ssh",
            "Driver": "local",
            "Mode": "",
            "RW": True,
            "Propagation": ""
        } 
    

回答1:

I still need to check the network part, but using the full path to the previous Source as the new source works to mount the volume.

update: volumes is a list of mount points (destination not the source).

import docker
containers = docker_api.containers()

docker_api.create_container(
    image='docker.site.fr:5000/coaxis/coaxisopt_daemon:latest', 
    volumes=['/home/mast/.ssh', '/etc/mast'], 
    host_config=docker_api.create_host_config(
        binds={
                "/var/lib/docker/volumes/841d6a1709b365763c85fb4b7400c87f264d468eb1691a660fe81761da6e374f/_data": {
                    'bind': "/home/mast/.ssh",
                    'mode': 'rw'
                },
                "/var/lib/docker/volumes/002730cbb4dd9b37ad808915a60081508885d533fe003b529b8d0ab4fa46e92e/_data": {
                    'bind': "/etc/mast",
                    'mode': 'rw'
                }
            }
    ))