Skip to content

Instantly share code, notes, and snippets.

@teocci
Last active November 16, 2022 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teocci/6610199ce14022b146825c6bb2667155 to your computer and use it in GitHub Desktop.
Save teocci/6610199ce14022b146825c6bb2667155 to your computer and use it in GitHub Desktop.
Basic configuration of docker for go and mariadb
version: '3.9'
services:
webapi:
build:
context: .
dockerfile: Dockerfile
container_name: webapi
restart: on-failure
depends_on:
- mariadb
ports:
- 8080:8080
mariadb:
image: mariadb
container_name: mariadb
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_DATABASE=testdb
- MYSQL_USER=kgh
- MYSQL_PASSWORD=1234
volumes:
- database:/var/lib/mysql
ports:
- 3306:3306
volumes:
api:
database:
# syntax=docker/dockerfile:1
FROM golang:alpine AS builder
RUN mkdir -p /go/src/app
WORKDIR /go/src/app
COPY . .
ENV CGO_ENABLED=0
RUN go get \
&& go mod download \
&& RUN go build -a -o webapi
FROM alpine
WORKDIR /app
COPY --from=builder /go/src/app/webapi /app/
ENV GO111MODULE="on"
ENV GIN_MODE="release"
EXPOSE 8080
CMD ["./webapi"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment