Dockerize golang application
Project
I have built TCP
based IoT
communication service with golang
. This service using mongodb
as the data storage. Following is the structure of the project.
Main motivation of golang is keep everything as simple as possible. So I have tried to build the service with minimum source files and packages. senz.go
is the main file. src
directory contains source files. build
directory contains build output file. Full source code of the project can be find from github
Dockerfile
Dockerfile is pretty straightforward. First I’m adding the base imagegolang 1.9
. Then I’m installing third party app gopkg.in/mgo.v2
which is the mongodb driver for golang. Then I’m compiling and generating build file into build/senz
. Finally adding the entry point docker-entrypoint.sh
which is a shell script.
Entrypoint
docker-entrypoint.sh
runs the build file that generated in build/senz
Build
docker build — tag erangaeb/zwitch:1.0 .
Push
docker push erangaeb/zwitch:1.0
Run
docker run \
-p 7070:7070 \
-e MONGO_HOST=10.2.2.3 \
erangaeb/zwitch:1.0