Running from source using docker

Hello!

I am going to run loraserver and lora-app-server in docker building them from source code.
I need it to continuously edit source code and deploy loraserver.
First I ran redis, mosquitto, postgres and gatewaybridge as docker containers using following docker-compose.yml:

    version: "2"

    services:
      gatewaybridge:
        image: loraserver/lora-gateway-bridge:2
        container_name: gatewaybridge_c
        network_mode: bridge
        ports:
          - 1700:1700/udp
        volumes:
          - ./configuration/lora-gateway-bridge:/etc/lora-gateway-bridge
      postgresql:
        image: postgres:9.6-alpine
        container_name: postgres_c
        network_mode: bridge
        ports:
          - "5432:5432"
        volumes:
          - ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d
          - ./data/postgresql:/var/lib/postgresql/data
      redis:
        image: redis:4-alpine
        container_name: redis_c
        network_mode: bridge
        ports:
          - "6379:6379"
        volumes:
          - ./data/redis:/data

      mosquitto:
        image: eclipse-mosquitto
        container_name: mosquitto_c
        network_mode: bridge
        ports:
          - "1883:1883"

with configuration files taken from loraserver-docker project on github

Seems that all is OK.

    $ docker ps
    CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                    NAMES
    5a19ad1c908a        redis:4-alpine                     "docker-entrypoint.s…"   44 minutes ago      Up 44 minutes       0.0.0.0:6379->6379/tcp   redis_c
    05224b5e4883        loraserver/lora-gateway-bridge:2   "./lora-gateway-brid…"   44 minutes ago      Up 44 minutes       0.0.0.0:1700->1700/udp   gatewaybridge_c
    0ff1f9490766        eclipse-mosquitto                  "/docker-entrypoint.…"   44 minutes ago      Up 44 minutes       0.0.0.0:1883->1883/tcp   mosquitto_c
    cd2cc9995e1a        postgres:9.6-alpine                "docker-entrypoint.s…"   44 minutes ago      Up 44 minutes       0.0.0.0:5432->5432/tcp   postgres_c

Then I checked availability of database containers from another container that I built using following compose file:

    version: "2"
    services:
      ubuntu:
        image: ubuntu
        external_links:
          - redis_c
        network_mode: bridge

and I was able to ping redis’s container:

    $ apt-get update
    $ apt-get install redis-tools
    $ env
    REDIS_C_PORT_6379_TCP=tcp://172.17.0.4:6379
    REDIS_C_PORT_6379_TCP_ADDR=172.17.0.4
    REDIS_C_NAME=/tmp_ubuntu_run_3_9fdef705db3b/redis_c
    REDIS_C_PORT_6379_TCP_PORT=6379
    REDIS_C_PORT_6379_TCP_PROTO=tcp
    REDIS_C_PORT=tcp://172.17.0.4:6379
    $ redis-cli -h redis_c -p 6379
    redis_c:6379> ping
    PONG

But when I try to run loraserver using following compose file:

    version: "2"
    services:
      loraserver:
        build:
          context: .
          dockerfile: Dockerfile-devel
        command: make serve
        volumes:
          - ./:/go/src/github.com/brocaar/loraserver
        external_links:
          - postgres_c
          - redis_c
          - mosquitto_c
        network_mode: bridge
        environment:
          - DB_AUTOMIGRATE=true
          - NET_ID=010203
          - BAND=EU_863_870
          - REDIS_URL=redis://redis:6379
          - GW_MQTT_SERVER=tcp://mosquitto:1883
          - GW_SERVER_JWT_SECRET=verysecret
          - POSTGRES_DSN=postgres://loraserver_ns:loraserver_ns@postgres/loraserver_ns?sslmode=disable
          - TEST_POSTGRES_DSN=postgres://loraserver_ns:loraserver_ns@postgres/loraserver_ns?sslmode=disable
          - TEST_REDIS_URL=redis://redis:6379
          - TEST_MQTT_SERVER=tcp://mosquitto:1883

with loraserver.toml placed in /etc/loraserver I got some error about redis and postgresql servers IP resolving:

$ make dev-requirements
$ make requirements
$ make test
Generating static files
Running tests
...
Given a clean Redis database time="2018-11-17T18:45:38Z" level=fatal msg="redis connection error: dial tcp: lookup redis on 67.207.67.2:53: no such host"
FAIL    github.com/brocaar/loraserver/internal/adr      0.032s
...
$ make build
$ ./build/loraserver
INFO[0000] starting LoRa Server                          band=EU_863_870 docs="https://docs.loraserver.io/" net_id=000000 version=2.3.0-2-g036a553
INFO[0000] setup redis connection pool                   url="redis://redis:6379"
INFO[0000] connecting to postgresql
ERRO[0000] ping database error, will retry in 2s: dial tcp: lookup postgresql on 67.207.67.2:53: no such host

Have no idea where does this IP is taken from.
But I am pretty sure that postgres and redis are accessible from loraserver container as their IP addresses resolved similar to test ubuntu container. I placed loraserver.toml file in expected directory but still without luck.
How to resolve this?
Maybe I forgot something?
I tried to do as described in documentation for this wonderful server.
Maybe there is easier way exist to build loraserver and lora-app-server from source code using docker? Cuz I don’t wont to run it on host and prefer to minimize amount of used databases (that’s why I ran it separately from loraserver and lora-app-server).

I got loraserver passed all tests and worked well by replacing:
dsn="postgres://loraserver_ns:loraserver_ns@postgresql/loraserver_ns?sslmode=disable" to dsn="postgres://loraserver_ns:loraserver_ns@172.17.0.5/loraserver_ns?sslmode=disable"
url="redis://redis:6379" to url="redis://172.17.0.3:6379" and server="tcp://mosquitto:1883" to server="tcp://172.17.0.6:1883"

Here is about network:

bash-4.4# cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.4      geoserver b5b4a78dec3c
172.17.0.6      mosquitto 5814396d9de1
172.17.0.5      postgres fcc0a328add2
172.17.0.3      redis de5d76800f82
172.17.0.7      f7d2c45daf92

bash-4.4# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 67.207.67.2
nameserver 67.207.67.3

bash-4.4# ping postgres
PING postgres (172.17.0.5): 56 data bytes
64 bytes from 172.17.0.5: seq=0 ttl=64 time=0.114 ms
64 bytes from 172.17.0.5: seq=1 ttl=64 time=0.116 ms

bash-4.4# ping redis
PING redis (172.17.0.3): 56 data bytes
64 bytes from 172.17.0.3: seq=0 ttl=64 time=0.120 ms
64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.129 ms

But still unable to use postgres, redis, mosquitto names in loraserver.toml file and need to replace them to ip addresses.