我尝试运行我的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
SDK
docker-py==1.10.6
在运行测试之前,我处于这种状态:
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
a4beb5d4de56 bridge bridge local
8a1012b67f1a host host local
ed2452ee5e44 none null local
没有集装箱运行$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
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"}'")
我正在使用相同的配置编写一个新测试,但忘记了在完成时销毁容器因此错误...
我发生了同样的错误。问题是不同服务器的docker版本。作为示例Ex:
所以我将所有服务器更新到18.03.1-ce的相同版本,现在它工作正常。