Running sourcegraph docker image on 0.0.0.0 instead of 127.0.0.1

985 Views Asked by At

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?

1

There are 1 best solutions below

0
On
--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.