gpt4 book ai didi

docker - create_network():无法分配网关(x.x.x.x):该地址已在测试用例中使用

转载 作者:行者123 更新时间:2023-12-02 02:48:43 38 4
gpt4 key购买 nike

我尝试运行我的test_container_services.py套件,但遇到了以下问题:


docker.errors.APIError:500服务器错误:内部服务器错误(“ b'{” message“:”无法分配网关(10.49.0.201):地址已在使用中“}'”)


我试图删除所有正在运行的容器和相关网络,但仍然遇到问题。

环保

核心

$ uname
Linux x1 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


码头工人

$ docker --version 
Docker version 1.13.1, build 092cba3


开发包

docker-py==1.10.6


Docker环境

在运行测试之前,我处于这种状态:

$ docker network ls
NETWORK ID NAME DRIVER SCOPE
a4beb5d4de56 bridge bridge local
8a1012b67f1a host host local
ed2452ee5e44 none null local


没有容器在运行
$ docker ps -a
容器ID图像命令创建的状态端口名称

测试

def test_get_network_config(self):
number_networks = len(self.docker_api.networks())
network_config = container_services.get_network_config(
data={
'ip': '10.49.0.1',
'subnet': '10.49.0.0/16',
'gateway': '10.49.0.201',
'vlan': 101
},
docker_client=self.docker_api
)
network_id = list(network_config.get('EndpointsConfig').keys())[0]

self.assertEqual(number_networks + 1, len(self.docker_api.networks()))
self.docker_api.remove_network(network_id)




def get_network_config(data, docker_client):
network = create_network(data, docker_client)
network_name = docker_client.inspect_network(network.get('Id')).get('Name')
network_info = dict()
network_info[network_name] = docker_client.create_endpoint_config(ipv4_address=data.get('ip'))
networking_config = docker_client.create_networking_config(network_info)
return networking_config


错误

ERROR: test_get_network_config (backend.api.tests.test_container_services.ContainersTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/projects/coaxis-opt/env/lib/python3.5/site-packages/docker/client.py", line 170, in _raise_for_status
response.raise_for_status()
File "/data/projects/coaxis-opt/env/lib/python3.5/site-packages/requests/models.py", line 909, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localunixsocket/v1.24/networks/create

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/projects/coaxis-opt/backend/api/tests/test_container_services.py", line 93, in test_get_network_config
docker_client=self.docker_api
File "/data/projects/coaxis-opt/backend/api/container_services.py", line 31, in get_network_config
network = create_network(data, docker_client)
File "/data/projects/coaxis-opt/backend/api/container_services.py", line 65, in create_network
options={"parent": get_default_interface(data)})
File "/data/projects/coaxis-opt/env/lib/python3.5/site-packages/docker/utils/decorators.py", line 35, in wrapper
return f(self, *args, **kwargs)
File "/data/projects/coaxis-opt/env/lib/python3.5/site-packages/docker/api/network.py", line 62, in create_network
return self._result(res, json=True)
File "/data/projects/coaxis-opt/env/lib/python3.5/site-packages/docker/client.py", line 178, in _result
self._raise_for_status(response)
File "/data/projects/coaxis-opt/env/lib/python3.5/site-packages/docker/client.py", line 174, in _raise_for_status
raise errors.APIError(e, response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'{"message":"failed to allocate gateway (10.49.0.201): Address already in use"}'")


相关: https://github.com/docker/docker-py/issues/1474

最佳答案

我正在用相同的配置编写新的测试,但是忘了在完成后销毁容器,因此出现了错误……

关于docker - create_network():无法分配网关(x.x.x.x):该地址已在测试用例中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42373954/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com