Connection refused and cannot assign requested address (Docker)

Viewed 322

I am trying to create a test environment using docker, where I have two python scripts dealing with connections. The first one, the one I want to test, opens a socket at 127.0.0.1:2947 to send and receive information. The second script launches a gpsfake process, that starts a dummy gpsd server on 127.0.0.1:2947. I do not need to connect from outside to the docker whatsoever, I just need it to start, launch the dummy server, launch the test script, and exit. However, when I first tried to do so after getting it to work on my local machine (without docker) I got the cannot assign requested address error both on the gpsfake process and the test process. After searching around for a bit I ended up creating a docker network and a docker-compose file to start the whole thing, and it looks like this:

version: '3.3'

networks:
  program-net:
    external: true

services:
  test:
    image: program-test
    ports:
      - 2947:2947
    networks:
      - program-net

The dockerfile for the test looks like this:

FROM python:3.8-slim-buster

RUN apt-get -y update && apt-get -y install apt-utils && apt-get -y install gpsd gpsd-clients socat
RUN mkdir -p /program
COPY . /program
WORKDIR /program
RUN pip3 install -r /program/requirements.txt
CMD ["python3", "/program/tools/integration_test.py"]

Now, when I start the docker using docker-compose -f program-docker-compose.yaml up, I get a Connection refused error from the python process, and if I try to start the gpsfake service myself, I get the cannot assign requested address error.

How can I fix this? All the information I can find online is to fix this type of issue for connections between dockers or between dockers and the host, but this does not require any connection outside the single docker that I have. What's going on?

0 Answers
Related