0

I created an linux application in GO consisting of a service myappd and a client myapp. I implemented a TCP based IPC on port 12345 between service and client hence the client could communicate with the service. If I run both on one machine, everything works fine. Now I want to containerize the service. Therefore I created a Dockerfile

FROM debian:buster
COPY ./src/* /home/
RUN chmod 777 /home/myappd
ENTRYPOINT /bin/bash /home/myapp_entrypoint.sh

with the entrypoint script

echo create log locations
mkdir /var/log/myappd
chmod 744 /var/log/myappd
touch /var/log/myappd/myappd.log
chmod 744 /var/log/myappd/myappd.log
cd /home/
./myappd

And build the image with

docker build -t myappd:latest .

Running the container with

docker run --rm --name myappd -itd -p 127.0.0.1:12345:12345 myappd:latest

Afterwards I check, if the service is running and if the port is exposed to the localhost

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                        NAMES
4caf95e1bd72        myappd:latest      "/bin/sh -c '/bin/ba…"   6 minutes ago       Up 2 seconds        127.0.0.1:12345->12345/tcp   myappd
$ sudo netstat -tulpn | grep LISTEN
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/init
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      520/sshd
tcp        0      0 127.0.0.1:12345         0.0.0.0:*               LISTEN      10673/docker-proxy
tcp6       0      0 :::111                  :::*                    LISTEN      1/init
tcp6       0      0 :::22                   :::*                    LISTEN      520/sshd

It is looking good for me. But when I start the client on localhost, the dial on port 12345 succeeds but each request on the port 12345 is responsed instantly with EOF and without any content. If I run the service locally the IPC can be reached on the port 12345 as expected

$ sudo netstat -tulpn | grep LISTEN
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/init
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      520/sshd
tcp        0      0 127.0.0.1:12345         0.0.0.0:*               LISTEN      13184/./myappd
tcp6       0      0 :::111                  :::*                    LISTEN      1/init
tcp6       0      0 :::22                   :::*                    LISTEN      520/sshd

Has anyone an idea why the IPC is working, when I run the service locally, but don't work if I run the service in a container?

FlorianSchunke
  • 571
  • 5
  • 15
  • 1
    What IP address is the server process listening on (can you show the `Listen()` call in your code)? If it's listening on 127.0.0.1 it won't be accessible from outside its container. – David Maze May 14 '21 at 11:06
  • Yes, it is listening on localhost. It is a good idea. The port act as local within the host but not in the container. From the container point of view the request comes from external. Good point. I will check – FlorianSchunke May 14 '21 at 12:04
  • Changing the IPC server component of my app to listen to requests from all clients, solving the issue. Thanks a lot @DavidMaze, maybe you could formulate your comment as an answer so I could accept it? – FlorianSchunke May 14 '21 at 12:37

0 Answers0