Consistent slowdown in HTTP requests made from inside a container

Expected behavior

A consistent rate of HTTP requests performed from inside a container.

Actual behavior

Approximately every 10th HTTP request will have a 3s delay, believed to be a TCP retransmission error.


I am running a simple python server on the host machine of the docker container. I then have a container with a very simple python (or java) application to send requests to the server. Roughly every 10 requests has a 3s delay.
With both script and server inside a single container I have no issue, with both outside equally there is no slowdown.


FROM python:3-windowsservercore-ltsc2016
ADD . .
RUN pip install requests
CMD ["python", ""]

import logging
import requests
                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S',
                    handlers=[logging.FileHandler(filename='test.log', mode='w'),
logger = logging.getLogger()
requests_log = logging.getLogger('requests.packages.urllib3')
requests_log.propagate = True

def main():
    ''' Main function '''
    url = 'http://<HOST IP>:666/endpoint'

    for i in range(500):
        requests.get(url=url)'Got response')

if __name__ == '__main__':

Python server:

import logging
from flask import Flask, request, jsonify
from flask_restful import Resource, Api

                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S',
                    handlers=[logging.FileHandler(filename='API_demo.log', mode='w'),
logger = logging.getLogger()

app = Flask(__name__)

api = Api(app)

class endpoint(Resource):
    def get(self):'recv')
        return {'success': True}

api.add_resource(endpoint, '/endpoint')

if __name__ == '__main__':'<HOST IP>', 666)

Steps to reproduce the behavior

Create container with dockerfile, run the server and container. Every 10th request has a 3s delay.

I’ve been struggling to find a possible reason why, be it network, OS, docker version, python version etc and have not found the cause.

Docker version 18.06.1-ce-win73 (19507)
Any help would be much appreciated!


I don’t see the same behaviour with a docker python alpine image: FROM python:3.7.0-alpine3.8
I’m running the client and server in the same docker network on ubuntu 16.04 LTS.
The 500 requests are handled within 4 seconds.