Skip to content

Instantly share code, notes, and snippets.

@nodece
Last active June 5, 2019 11:23
Show Gist options
  • Save nodece/00b5b6b0df017736fd04270ac116696c to your computer and use it in GitHub Desktop.
Save nodece/00b5b6b0df017736fd04270ac116696c to your computer and use it in GitHub Desktop.
Deploy the Golang application to Docker

Build script

#!/bin/sh

dockerId="docker-id"
imageName="go-application"

tag="${dockerId}/${imageName}"
docker build -t "${tag}" .
docker build -t dockerId/imageName .

Run script

#!/bin/sh

dockerId="docker-id"
imageName="go-application"
containerName="go-application"

tag="${dockerId}/${imageName}"

docker run -p 9000:9000 -d --name "${containerName}" tag
docker run -p 9000:9000 -d --name go-application dockerId/imageName
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
docker build -t $(dockerId)/$(imageName) .
docker login -u $(dockerId) -p $(dockerPassword)
docker push $(dockerId)/$(imageName)
FROM golang:alpine as build-env
RUN apk update
RUN apk add --no-cache git
ADD . /app/
WORKDIR /app
ENV GOPROXY https://goproxy.io
RUN go mod download
RUN go build -o main .
FROM alpine:latest
COPY --from=build-env /app/main /app/main
RUN apk update
RUN apk add --no-cache tzdata
EXPOSE 9000
ENTRYPOINT ["/app/main"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment