Skip to content

Instantly share code, notes, and snippets.

@mattbennett
Forked from kooba/Dockerfile
Last active December 20, 2016 18:12
Show Gist options
  • Save mattbennett/b0340fedd8a8f1fecd47cba26c7bec6b to your computer and use it in GitHub Desktop.
Save mattbennett/b0340fedd8a8f1fecd47cba26c7bec6b to your computer and use it in GitHub Desktop.
dnspython docker dns issue
version: "2"
services:
test-service:
container_name: test-service
image: busybox
command: ['/bin/sh', '-c', 'sleep 5']
test-client-eventlet:
container_name: test-client-eventlet
build:
context: .
dockerfile: Dockerfile.eventlet
dns_search: foo.example.com
test-client-unpatched:
container_name: test-client-unpatched
build:
context: .
dockerfile: Dockerfile.unpatched
dns_search: foo.example.com
FROM python:3.4
RUN pip install eventlet
COPY test.py /var/tmp/test.py
CMD [ "python", "/var/tmp/test.py" ]
FROM python:3.4
COPY test.py /var/tmp/test.py
CMD [ "python", "/var/tmp/test.py" ]
monkeypatched = False
try:
import eventlet
eventlet.monkey_patch()
monkeypatched = True
except ImportError:
monkeypatched = False
import socket
service_url = 'test-service'
print('### monkeypatched? {} ###'.format(monkeypatched))
ip_list = []
ais = socket.getaddrinfo(service_url, 0, 0, 0, 0)
for result in ais:
ip_list.append(result[-1][0])
ip_list = list(set(ip_list))
print(ip_list[0])
@mattbennett
Copy link
Author

Expected output:

$ docker-compose up
Starting test-service
Recreating test-client-eventlet
Recreating test-client-unpatched
Attaching to test-service, test-client-eventlet, test-client-unpatched
test-client-eventlet     | ### monkeypatched? True ###
test-client-eventlet    | 172.20.0.2
test-client-unpatched    | ### monkeypatched? False ###
test-client-unpatched    | 172.20.0.2

Actual output:

$ docker-compose up
Starting test-service
Recreating test-client-eventlet
Recreating test-client-unpatched
Attaching to test-service, test-client-eventlet, test-client-unpatched
test-client-eventlet     | ### monkeypatched? True ###
test-client-eventlet     | Traceback (most recent call last):
test-client-eventlet     |   File "/var/tmp/test.py", line 17, in <module>
test-client-eventlet     |     ais = socket.getaddrinfo(service_url, 0, 0, 0, 0)
test-client-eventlet     |   File "/usr/local/lib/python3.4/site-packages/eventlet/support/greendns.py", line 464, in getaddrinfo
test-client-eventlet     |     raise socket.gaierror(socket.EAI_NONAME, 'No address found')
test-client-eventlet     | socket.gaierror: [Errno -2] No address found
test-client-unpatched    | ### monkeypatched? False ###
test-client-unpatched    | 172.20.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment