title: Docker container unable to access external IP addresses on same network
body: <p>I am trying to get a python docker container to run. The container starts up, but I am unable to get pyodbc to login to an external MSSQL server. I get the error login timed out.</p>
  <p>When I connect to the docker container with</p>
  <pre><code>docker exec -it 7f4 /bin/bash
  </code></pre>
  <p>and run <code>ping 192.168.10.3</code>, which is the IP Address of the host machine and where SQL Server is running, I get nothing back. Not even, no reply.</p>
  <p>If I <code>ping localhost</code> that works just fine, but obviously that is just the localhost inside the container.</p>
  <p>Here is my Dockerfile</p>
  <pre><code>FROM python:3.7.4-stretch
  
  RUN apt-get update \
  
  # &amp;&amp; apt-get install g++ \
  
  &amp;&amp; apt-get install --yes unixodbc-dev \
  
  &amp;&amp; pip install pyodbc==4.0.27
  
  # --- Install Microsoft ODBC Driver
  
  # https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
  
  RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
  
  RUN curl https://packages.microsoft.com/config/debian/9/prod.list &gt; /etc/apt/sources.list.d/mssql-release.list
  
  # Need some certificate fix to install msodbcsql17
  
  RUN apt-get install --yes apt-transport-https ca-certificates \
  
  &amp;&amp; apt-get update &amp;&amp; ACCEPT_EULA=Y apt-get install --yes msodbcsql17
  
  WORKDIR /app
  
  
  
  COPY requirements.txt .
  
  RUN pip install -r requirements.txt
  
  COPY . /app
  CMD [ &quot;uvicorn&quot;, &quot;app:app&quot;, &quot;--port&quot;, &quot;8000&quot;]
  </code></pre>
  <p>and here is the error that I get</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/usr/local/bin/uvicorn&quot;, line 8, in &lt;module&gt;
      sys.exit(main())
    File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 829, in __call__
      return self.main(*args, **kwargs)
    File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 782, in main
      rv = self.invoke(ctx)
    File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 1066, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File &quot;/usr/local/lib/python3.7/site-packages/click/core.py&quot;, line 610, in invoke
      return callback(*args, **kwargs)
    File &quot;/usr/local/lib/python3.7/site-packages/uvicorn/main.py&quot;, line 355, in main
      run(**kwargs)
    File &quot;/usr/local/lib/python3.7/site-packages/uvicorn/main.py&quot;, line 379, in run
      server.run()
    File &quot;/usr/local/lib/python3.7/site-packages/uvicorn/main.py&quot;, line 407, in run
      loop.run_until_complete(self.serve(sockets=sockets))
    File &quot;/usr/local/lib/python3.7/asyncio/base_events.py&quot;, line 579, in run_until_complete
      return future.result()
    File &quot;/usr/local/lib/python3.7/site-packages/uvicorn/main.py&quot;, line 414, in serve
      config.load()
    File &quot;/usr/local/lib/python3.7/site-packages/uvicorn/config.py&quot;, line 300, in load
      self.loaded_app = import_from_string(self.app)
    File &quot;/usr/local/lib/python3.7/site-packages/uvicorn/importer.py&quot;, line 20, in import_from_string
      module = importlib.import_module(module_str)
    File &quot;/usr/local/lib/python3.7/importlib/__init__.py&quot;, line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1006, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;./app.py&quot;, line 21, in &lt;module&gt;
      cursor = db.get_cursor(db.get_db_connection())
    File &quot;./db.py&quot;, line 8, in get_db_connection
      return pyodbc.connect(f&quot;DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={os.getenv('DB_HOST')},{os.getenv('DB_PORT')};DATABASE={os.getenv('DB_DATABASE')};UID={os.getenv('DB_USERNAME')};PWD={os.getenv('DB_PASSWORD')}&quot;)
  pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
  </code></pre>