From bcf4e98062df980d1e6f26dc1c200d5e70913256 Mon Sep 17 00:00:00 2001 From: ansh0014 Date: Tue, 10 Feb 2026 14:57:12 +0530 Subject: [PATCH] Fix Docker build failure and configuration issues - Update Dockerfile from Go 1.14 to Go 1.21-alpine - Implement multi-stage build for smaller image size - Add MySQL root password in docker-compose.yaml - Fix article-server command path (article-server -> ./article-server) - Add proper volume mount for config file (local.yaml -> config.yaml) - Add depends_on to ensure MySQL starts before article-server - Include build context and dockerfile specification These changes resolve Docker build failures and runtime configuration errors." --- cmd/server/Dockerfile | 25 ++++++++++++++++--------- docker-compose.yaml | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cmd/server/Dockerfile b/cmd/server/Dockerfile index ba17eea..0e53626 100644 --- a/cmd/server/Dockerfile +++ b/cmd/server/Dockerfile @@ -1,11 +1,18 @@ -FROM golang:1.14-alpine AS build - -RUN mkdir -p /go/src/github.com/zacscoding/gin-rest-api-example ~/.ssh && \ - apk add --no-cache git openssh-client make gcc libc-dev -WORKDIR /go/src/github.com/zacscoding/gin-rest-api-example +FROM golang:1.21-alpine AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download COPY . . -RUN make build +RUN CGO_ENABLED=0 GOOS=linux go build -o article-server ./cmd/server +FROM alpine:latest + +RUN apk --no-cache add ca-certificates tzdata + +WORKDIR /app +COPY --from=builder /app/article-server . +COPY --from=builder /app/config ./config +COPY --from=builder /app/migrations ./migrations + +EXPOSE 8080 -FROM alpine:3 -COPY --from=build /go/src/github.com/zacscoding/gin-rest-api-example/article-server /bin/article-server -CMD /bin/article-server \ No newline at end of file +CMD ["./article-server"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index f67f1c9..b575ad8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -51,7 +51,7 @@ services: volumes: - ./config/local.yaml:/config/config.yaml - ./migrations:/config/migrations - command: article-server --conf /config/config.yaml + command: ./article-server --conf /config/config.yaml restart: always depends_on: - "db"