如何使用以前的网络和卷升级Docker容器

如何使用以前的网络和卷升级Docker容器

本文介绍了如何使用以前的网络和卷升级Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我们与卷和自定义网络。

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.

然而,我不知道我真的需要抓住旧的容器以及如何使用它。例如,

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


  • NetworkSettings.Networks 足够或其他地方有网络信息数据?

  • 如何使用中的信息安装卷?

  • 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": ""
    }

li>

推荐答案

我仍然需要检查网络部分,但使用前面的code>源,因为新的源代码可以安装。

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

这篇关于如何使用以前的网络和卷升级Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:54