docker build

This commit is contained in:
JurajKubrican
2024-10-29 08:51:25 +01:00
parent 3d94ad1009
commit 6bd3bddbd9
4 changed files with 22 additions and 6 deletions

View File

@@ -4,4 +4,4 @@ services:
web: web:
image: ghcr.io/jurajkubrican/knet/go-web-server:latest image: ghcr.io/jurajkubrican/knet/go-web-server:latest
ports: ports:
- 5000:5000/tcp - 54321:54321/tcp

View File

@@ -1,14 +1,30 @@
# Step 1: Build the Go binary # Step 1: Build the Go binary in a separate stage
FROM golang:1.23 AS builder
# Set the working directory
WORKDIR /app
# Copy the Go module files
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the application code
COPY . .
# Build the Go binary with static linking for Linux
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server src/main.go
FROM scratch FROM scratch
# Set the current working directory inside the container # Set the current working directory inside the container
WORKDIR /app WORKDIR /app
# Copy go.mod and go.sum files COPY . .
COPY server ./ COPY --from=builder server ./
# Command to run the executable # Command to run the executable
CMD ["./server"] CMD ["./server"]
# Expose the port on which the Go server will run # Expose the port on which the Go server will run
EXPOSE 80 EXPOSE 54321

BIN
server

Binary file not shown.

View File

@@ -43,5 +43,5 @@ func main() {
return c.Render(200, "index", page) return c.Render(200, "index", page)
}) })
e.Logger.Fatal(e.Start(":5000")) e.Logger.Fatal(e.Start(":54321"))
} }