Skip to content

Commit

Permalink
chore(docker): add docker file and use docker network connect postgre…
Browse files Browse the repository at this point in the history
…sql and go container
  • Loading branch information
eizyc committed Jun 24, 2024
1 parent 78550fe commit b278585
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Build stage
FROM golang:1.22.4-alpine3.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o main main.go

# Run stage
FROM alpine:3.20
WORKDIR /app
COPY --from=builder /app/main .
COPY app.env .
EXPOSE 8080
CMD ["/app/main"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DB_URL=postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable

postgres:
docker run --name postgres16 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:16-alpine
docker run --name postgres16 --network bank-network -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:16-alpine

createdb:
docker exec -it postgres16 createdb --username=root --owner=root simple_bank
Expand Down
17 changes: 16 additions & 1 deletion markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@ make createdb
``` shell
migrate -path db/migration/ -database "postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable" -verbose up
```

#### install golang-migrate
```
brew install golang-migrate
```

#### How to make a new version database migration aka. the database need to change some schema
```
make new_migration
```

#### How to build the docker and build docker network includes postgresql and go container
```
\\ build image, in the Dockerfile folder
docker build -t simplebank:last .
\\ create docker network
docker network create bank-network
\\ connect network to postgresql container
docker network connect bank-network postgres16
\\ container
docker run --name simplebank --network bank-network -p 8080:8080 -e GIN_MODE=release -e DB_SOURCE="postgresql://root:secret@postgres16:5432/simple_bank?sslmode=disable" simplebank:last
```

0 comments on commit b278585

Please sign in to comment.