How to build the Docker image


#1

Hi all

I deploy the server by docker ,and it works well

I have modifyed the go project source code,and build successfully

my question
1、I want to repalce the bin file in docker,and use my new build file ,how? I cannot find any bin file in docker project

2、Or I must use the “general installation”,not “ Docker install” ?

thanks and regards!


#2

You probably want to create a new Docker image, please see the provided Dockerfile in each repository.


#3

Hi brocaar

Thanks for your reply!

yes,I need a new Docker image

I find the “Dockerfile”,But I have not find the introduction about how to make a new Docker image use the “Dockerfile”

And if I make the new Docker image successfully,How to use the image by docker-compose?

Best regards!


#4

When you modifying the LoRa Server source and wish to create custom Docker images, then I leave how to use Docker as your exercise :wink: https://docs.docker.com/ is a good starting point and contains lots of information about how to build Docker images and use them with Docker Compose.


#5

Document is enough! thank you


#6

Hi brocaar

there is a problem when I try to create a Docker image

1、I can build the loraserver go project successfully

[root@localhost loraserver]# make
Generating static files
Compiling source
go build -ldflags “-s -w -X main.version=2.3.0-2-g036a553” -o build/loraserver cmd/loraserver/main.go

2、I can run go-bindata ok

[root@localhost loraserver]# go-bindata -version
go-bindata 3.1.0 (Go runtime go1.11.2).
Copyright © 2010-2013, Jim Teeuwen.

3、but when I create a docker image,It shows like blew

[root@localhost loraserver]# docker build -t lora_app_image .
… …
Step 10/15 : RUN make
—> Running in 39f4ea7127d6
Generating static files
cmd/loraserver/main.go:1: running “go-bindata”: exec: “go-bindata”: executable file not found in $PATH
make: *** [Makefile:46: statics] Error 1
The command ‘/bin/sh -c make’ returned a non-zero code: 2


makefile linenum 46
46 @go generate cmd/loraserver/main.go

Any help will be appreciate!


#7

There is no need to first compile the source and then build the Docker image, this is all done by Docker for you, see also the Dockerfile.

Example:

$ git clone git@github.com:brocaar/loraserver.git
$ cd loraserver

# make all the modifications that you want to make

$ docker build -t my_custom_loraserver .

Then you can use the image my_custom_loraserver (instead of brocaar/loraserver) e.g. in your docker-compose.yml file.

See below the log for the Docker build of the current master branch:

~ $ cd /tmp/
/tmp $ git clone git@github.com:brocaar/loraserver.git
Cloning into 'loraserver'...
remote: Enumerating objects: 249, done.
remote: Counting objects: 100% (249/249), done.
remote: Compressing objects: 100% (158/158), done.
remote: Total 9516 (delta 119), reused 174 (delta 79), pack-reused 9267
Receiving objects: 100% (9516/9516), 6.82 MiB | 9.25 MiB/s, done.
Resolving deltas: 100% (5328/5328), done.
/tmp $ cd loraserver/
/t/loraserver (master|✔) $ docker build -t my_custom_loraserver .
Sending build context to Docker daemon  9.297MB
Step 1/16 : FROM golang:1.11-alpine AS development
 ---> f56365ec0638
Step 2/16 : ENV PROJECT_PATH=/go/src/github.com/brocaar/loraserver
 ---> Running in ce4b4a3c8a22
Removing intermediate container ce4b4a3c8a22
 ---> 3950eee42f2d
Step 3/16 : ENV PATH=$PATH:$PROJECT_PATH/build
 ---> Running in 9d90f415ce98
Removing intermediate container 9d90f415ce98
 ---> 1be92192192c
Step 4/16 : ENV CGO_ENABLED=0
 ---> Running in b2c19959fc2e
Removing intermediate container b2c19959fc2e
 ---> 5236318fc9b0
Step 5/16 : ENV GO_EXTRA_BUILD_ARGS="-a -installsuffix cgo"
 ---> Running in 1c93f4b427a3
Removing intermediate container 1c93f4b427a3
 ---> c78b6d08e5bb
Step 6/16 : RUN apk add --no-cache ca-certificates tzdata make git bash protobuf
 ---> Running in 4c96350bd9e1
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/16) Installing ncurses-terminfo-base (6.1_p20180818-r1)
(2/16) Installing ncurses-terminfo (6.1_p20180818-r1)
(3/16) Installing ncurses-libs (6.1_p20180818-r1)
(4/16) Installing readline (7.0.003-r0)
(5/16) Installing bash (4.4.19-r1)
Executing bash-4.4.19-r1.post-install
(6/16) Installing nghttp2-libs (1.32.0-r0)
(7/16) Installing libssh2 (1.8.0-r3)
(8/16) Installing libcurl (7.61.1-r1)
(9/16) Installing expat (2.2.5-r0)
(10/16) Installing pcre2 (10.31-r0)
(11/16) Installing git (2.18.1-r0)
(12/16) Installing make (4.2.1-r2)
(13/16) Installing libgcc (6.4.0-r9)
(14/16) Installing libstdc++ (6.4.0-r9)
(15/16) Installing protobuf (3.5.2-r0)
(16/16) Installing tzdata (2018f-r0)
Executing busybox-1.28.4-r2.trigger
OK: 37 MiB in 30 packages
Removing intermediate container 4c96350bd9e1
 ---> d0641f65fe8f
Step 7/16 : RUN mkdir -p $PROJECT_PATH
 ---> Running in 4be6b8b1b438
Removing intermediate container 4be6b8b1b438
 ---> 5e41c17ef37f
Step 8/16 : COPY . $PROJECT_PATH
 ---> 51ef7a54a18a
Step 9/16 : WORKDIR $PROJECT_PATH
 ---> Running in 8e6219247e08
Removing intermediate container 8e6219247e08
 ---> d064742171f5
Step 10/16 : RUN make dev-requirements requirements
 ---> Running in 29e66d5daf74
go get -u github.com/kisielk/errcheck
go get -u golang.org/x/lint/golint
go get -u github.com/smartystreets/goconvey
go get -u golang.org/x/tools/cmd/stringer
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/elazarl/go-bindata-assetfs/...
go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/golang/dep/cmd/dep
go get -u github.com/goreleaser/goreleaser
go get -u github.com/goreleaser/nfpm
dep ensure -v
(1/50) Wrote github.com/sirupsen/logrus@v1.3.0
(2/50) Wrote golang.org/x/crypto@master
(3/50) Wrote github.com/gofrs/uuid@v3.2.0
(4/50) Wrote github.com/fsnotify/fsnotify@v1.4.7
(5/50) Wrote cloud.google.com/go@v0.34.0
(6/50) Wrote github.com/brocaar/lorawan@master
(7/50) Wrote github.com/davecgh/go-spew@v1.1.1
(8/50) Wrote github.com/rubenv/sql-migrate@master
(9/50) Wrote github.com/NickBall/go-aes-key-wrap@master
(10/50) Wrote github.com/eclipse/paho.mqtt.golang@v1.1.1
(11/50) Wrote golang.org/x/text@v0.3.0
(12/50) Wrote gopkg.in/yaml.v2@v2.2.2
(13/50) Wrote google.golang.org/grpc@v1.18.0
(14/50) Wrote google.golang.org/appengine@v1.4.0
(15/50) Wrote github.com/gomodule/redigo@v2.0.0
(16/50) Wrote github.com/googleapis/gax-go@v2.0.3
(17/50) Wrote google.golang.org/genproto@master
(18/50) Wrote github.com/golang/protobuf@v1.2.0
(19/50) Wrote github.com/gopherjs/gopherjs@master
(20/50) Wrote github.com/inconshreveable/mousetrap@v1.0
(21/50) Wrote github.com/hashicorp/hcl@v1.0.0
(22/50) Wrote github.com/jmoiron/sqlx@master
(23/50) Wrote gonum.org/v1/gonum@master
(24/50) Wrote github.com/jtolds/gls@v4.20
(25/50) Wrote github.com/grpc-ecosystem/go-grpc-middleware@v1.0.0
(26/50) Wrote github.com/konsorten/go-windows-terminal-sequences@v1.0.1
(27/50) Wrote gopkg.in/gorp.v1@v1.7.2
(28/50) Wrote github.com/magiconair/properties@v1.8.0
(29/50) Wrote github.com/lib/pq@master
(30/50) Wrote github.com/jacobsa/crypto@master
(31/50) Wrote golang.org/x/exp@master
(32/50) Wrote github.com/mitchellh/mapstructure@v1.1.2
(33/50) Wrote github.com/pkg/errors@v0.8.1
(34/50) Wrote github.com/pmezard/go-difflib@v1.0.0
(35/50) Wrote github.com/pelletier/go-toml@v1.2.0
(36/50) Wrote golang.org/x/sync@master
(37/50) Wrote golang.org/x/oauth2@master
(38/50) Wrote github.com/smartystreets/assertions@1.8.3
(39/50) Wrote golang.org/x/net@master
(40/50) Wrote github.com/spf13/afero@v1.2.0
(41/50) Wrote github.com/spf13/cast@v1.3.0
(42/50) Wrote github.com/smartystreets/goconvey@1.6.3
(43/50) Wrote github.com/spf13/cobra@v0.0.3
(44/50) Wrote github.com/spf13/jwalterweatherman@v1.0.0
(45/50) Wrote github.com/spf13/pflag@v1.0.3
(46/50) Wrote golang.org/x/sys@master
(47/50) Wrote github.com/spf13/viper@v1.3.1
(48/50) Wrote github.com/stretchr/testify@v1.3.0
(49/50) Wrote go.opencensus.io@v0.18.0
(50/50) Wrote google.golang.org/api@v0.1.0
Removing intermediate container 29e66d5daf74
 ---> 22928b749073
Step 11/16 : RUN make
 ---> Running in 610d26fcd684
Generating static files
Compiling source
go build -a -installsuffix cgo -ldflags "-s -w -X main.version=2.4.1-6-g78e264d" -o build/loraserver cmd/loraserver/main.go
Removing intermediate container 610d26fcd684
 ---> df32d5b452c5
Step 12/16 : FROM alpine:latest AS production
latest: Pulling from library/alpine
cd784148e348: Already exists
Digest: sha256:46e71df1e5191ab8b8034c5189e325258ec44ea739bba1e5645cff83c9048ff1
Status: Downloaded newer image for alpine:latest
 ---> 3f53bb00af94
Step 13/16 : WORKDIR /root/
 ---> Running in d189518fc20f
Removing intermediate container d189518fc20f
 ---> e2e5eb5479bc
Step 14/16 : RUN apk --no-cache add ca-certificates tzdata
 ---> Running in f2e00900ced0
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/2) Installing ca-certificates (20171114-r3)
(2/2) Installing tzdata (2018f-r0)
Executing busybox-1.28.4-r2.trigger
Executing ca-certificates-20171114-r3.trigger
OK: 8 MiB in 15 packages
Removing intermediate container f2e00900ced0
 ---> 84dd438b332b
Step 15/16 : COPY --from=development /go/src/github.com/brocaar/loraserver/build/loraserver .
 ---> 5af3324a76d3
Step 16/16 : ENTRYPOINT ["./loraserver"]
 ---> Running in 1dc88bfeef03
Removing intermediate container 1dc88bfeef03
 ---> 3c2527416a68
Successfully built 3c2527416a68
Successfully tagged my_custom_loraserver:latest

#8

Hi brocaar

It work now! thank you :slightly_smiling_face: