0

I am trying to run sourcegraph service on a remote machine. The instructions to run sourcegraph is given as

https://about.sourcegraph.com/docs/server

docker run \
 --publish 7080:7080 --rm \
 --volume /tmp/sourcegraph/config:/etc/sourcegraph \
 --volume /tmp/sourcegraph/data:/var/opt/sourcegraph \
 sourcegraph/server:2.3.11

This runs sourcegraph at 127.0.0.1 I want to run at 0.0.0.0 so that I can access the service from remote machines.

Trying this doesn't work.

docker run --publish 0.0.0.0:7080:7080 ...

It says, it is running the service on

Sourcegraph is now running at http://localhost:7080

Any suggestions? Could this be sourcegraph's problem?

beyang
  • 505
  • 3
  • 8
Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131
  • 2
    This is sourcegraph's problem. Docker is listening with 7080 on the host on all interfaces by default. But it can't reach the app inside the container because that app is listening on 127.0.0.1. – BMitch Jan 04 '18 at 17:34
  • Hi Senthil, is this still an issue for you? Filed here to track: https://github.com/sourcegraph/issues/issues/118. More than happy to help you set this up if you're still trying to do so! – beyang Aug 06 '18 at 19:33

1 Answers1

0
--publish 7080:7080

That option causes docker to listen on all host interfaces and forward traffic from host port 7080 to the container's port 7080. The container must be listening on all interfaces inside its network namespace for this to work (docker cannot talk to the loopback interface inside the container's network namespace).

Sourcegraph is now running at http://localhost:7080

This is actually a misleading message from your application (this doesn't come from docker itself). Testing this image with netshoot shows that the container is listening on all interfaces:

$ docker ps
CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS                    PORTS               NAMES
687f9749d99c        sourcegraph/server:2.3.11        "/sbin/tini -- /usr/…"   43 minutes ago      Up 43 minutes                                 keen_torvalds
...

$ docker run -it --rm --net container:687f9749d99c nicolaka/netshoot /bin/sh
/ # netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      
tcp        0      0 127.0.0.1:5005          0.0.0.0:*               LISTEN      
tcp        0      0 127.0.0.1:3700          0.0.0.0:*               LISTEN      
tcp        0      0 :::7080                 :::*                    LISTEN      
tcp        0      0 :::3178                 :::*                    LISTEN      
tcp        0      0 :::3179                 :::*                    LISTEN      
tcp        0      0 :::6379                 :::*                    LISTEN      
tcp        0      0 :::6060                 :::*                    LISTEN      
tcp        0      0 :::3180                 :::*                    LISTEN      
tcp        0      0 :::3181                 :::*                    LISTEN      
tcp        0      0 :::3090                 :::*                    LISTEN 

Note the :::7080 line shows the container is listening for this port on all interfaces. As long as your network allows it, you should be able to reach your container by going the host IP, port 7080.

BMitch
  • 231,797
  • 42
  • 475
  • 450