Skip to content

Instantly share code, notes, and snippets.

@pot-code
Last active April 15, 2021 16:20
Show Gist options
  • Save pot-code/f8f48c7c6c671c3478f5e66d3e9de7ae to your computer and use it in GitHub Desktop.
Save pot-code/f8f48c7c6c671c3478f5e66d3e9de7ae to your computer and use it in GitHub Desktop.
[go dockerfile] dockerfile templates #docker
FROM golang:1.16 as builder
WORKDIR /go/src
COPY go.mod .
COPY go.sum .
RUN go mod download
# build delve
RUN go get github.com/go-delve/delve/cmd/dlv
COPY . .
# build prod app
RUN GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w -X 'main.EnvPrefix=GO'" -o app ./cmd
# build debug app
RUN GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -gcflags "all=-N -l" -ldflags="-X 'main.EnvPrefix=GO'" -o debug ./cmd
FROM alpine:3.8
RUN apk add --no-cache libc6-compat
WORKDIR /usr/bin/go
COPY --from=builder ["/go/src/config.yaml", "/go/src/jwt-pub.pem", "/go/src/app", "/go/src/debug", "/go/bin/dlv", "./"]
RUN chmod 0755 app
RUN chmod 0755 debug
EXPOSE 8081 2345
CMD [ "./app" ]
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/Dockerfile*
*.toml
*.js
.vscode
.editorconfig
app
tmp
db
ports:
- containerPort: 8081
- containerPort: 2345
command:
[
'./dlv',
'--listen=:2345',
'--headless=true',
'--log',
'--api-version=2',
'--accept-multiclient',
'exec',
'./debug',
]
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"cwd": "${workspaceFolder}"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment