How to upgrade docker container with previous network and volumes?

爱⌒轻易说出口 提交于 2019-12-12 04:47:18

问题


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'
                }
            }
    ))


来源:https://stackoverflow.com/questions/42488732/how-to-upgrade-docker-container-with-previous-network-and-volumes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!