Go in Docker
go github docker
Published: 2019-10-10

How do deploy an application in docker?

Start with a simple Go application that echos back a response.

curl http://<host>/echo/ping
#=> pong

Code for the server is hosted at :

git clone https://github.com/bilal-bhatti/echo.git

Build docker image

cd echo
env GOOS=linux GOARCH=amd64 go build -o ./dist/echo-linux-amd64
docker build -t $GIT_USER/echo/linux-amd64 .

Dockerfile is using the scratch base image, adding our binary, and specifying the start command.

FROM scratch

ADD "https://curl.haxx.se/ca/cacert.pem" "/etc/ssl/certs/ca-certificates.crt"
ADD "./dist/echo-linux-amd64" "/echo"
ENTRYPOINT ["/echo"]

Run image

docker run -d -p 8888:8888 $GIT_USER/echo/linux-amd64 -listen ":8888"

Test

curl localhost:8888/echo/ping
#=> pong