Python throwing socket.gaierror suddenly

Viewed 135

I've had a setup of a docker container which has been running previously and suddenly in the past few days for some reason I can not get it's address with the python socket module.

Basically I have a UnitTest class:

import socket, unittest

class UnitTest(unittest.TestCase):

    def setUpClass(self):
        cls.container_address = socket.gethostbyname("container_name")
        ....

And I have a docker image which I spin up by using a docker-compose.yml

version: "2.3"
services:
  container_name:
    image: container_image:latest
    build:
       context: ./
    container_name: container_name
    ports:
      - "10021:10021"
      - "10022:10022"
      - "10023:10023"
    restart: unless-stopped

Previously, the unit test class would work fine, it would find the container on my network and retrieve the proper IP address for it so that I can start a client for it to test. Without much explanation however, in the past days this has started to fail and it can not find anymore the container. I've checked the naming to be sure that they are correct and nothing changed. I keep getting the socket.gaierror however. This error does not happen however when I run my container on my gitlab ci pipeline, only when I run it on my local machine. I'm at a loss for what can the cause be. Any tips on this would be appreciated.

0 Answers
Related