Dockerfile:
# Build stage FROM golang:1.21.5-alpine3.18 AS builder WORKDIR /app COPY . . RUN go env -w GOPROXY=https://goproxy.io,direct RUN go build -o main main.go # Run stage FROM alpine:3.18 WORKDIR /app COPY --from=builder /app/main . COPY app.env . EXPOSE 8080 CMD [ "/app/main"]
zzh@ZZHPC:/zdata/Github/zimplebank$ docker build -t zimplebank:latest .
zzh@ZZHPC:/zdata/Github/zimplebank$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE zimplebank latest 1ab108eea809 About a minute ago 25.4MB
Use network to connect two standalone containers (postgres16 and zimplebank):
zzh@ZZHPC:/zdata/Github/zimplebank$ docker network create zbank-network
zzh@ZZHPC:/zdata/Github/zimplebank$ docker network connect zbank-network postgres16
Run the container with --network:
zzh@ZZHPC:/zdata/Github/zimplebank$ docker run --name zimplebank --network zbank-network -p 8080:8080 -e GIN_MODE=release -e DB_SOURCE="postgresql://root:aaa@postgres16:5432/zimple_bank?sslmode=disable" zimplebank:latest
zzh@ZZHPC:~$ docker network inspect zbank-network
...... "Containers": { "5d50a55a684a6c14e1c04e6416b0c7380b2cce308a96c7fd27bbe02c47703a46": { "Name": "zimplebank", "EndpointID": "4fccd5618a1721e37d440d473677029e1ea2643c6eebce4beb469412553e8061", "MacAddress": "02:42:ac:12:00:03", "IPv4Address": "172.18.0.3/16", "IPv6Address": "" }, "7a740db38f9844c63bb5b5b4ab8ebd8dc51b0403b669cbd55612b30cbf3b86a5": { "Name": "postgres16", "EndpointID": "c6f4c3a44bbfb98c186ef685be02e119730ad676bb9f2e2acaee026b951eb3ac", "MacAddress": "02:42:ac:12:00:02", "IPv4Address": "172.18.0.2/16", "IPv6Address": "" } }, ......