我试图在我的docker容器内运行迁移,当尝试运行迁移命令时,我得到以下错误
当我运行docker compose up而不使用migration命令时
/app/migrate -path /app/migration -database "$DB_SOURCE" -verbose up
应用程序构建良好,我的数据库源是
DB_SOURCE = "postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable"
simplebank-api-1 | run db migration
simplebank-api-1 | fatal: morestack on g0
simplebank-api-1 | SIGTRAP: trace trap
simplebank-api-1 | PC=0x80a8242 m=1 sigcode=128
simplebank-api-1 |
simplebank-api-1 | goroutine 0 [idle]:
simplebank-api-1 | runtime.abort()
simplebank-api-1 | runtime/asm_386.s:847 +0x2
simplebank-api-1 | runtime.morestack()
simplebank-api-1 | runtime/asm_386.s:422 +0x24
simplebank-api-1 |
simplebank-api-1 | goroutine 1 [running, locked to thread]:
simplebank-api-1 | goroutine running on other thread; stack unavailable
simplebank-api-1 |
simplebank-api-1 | eax 0x17
simplebank-api-1 | ebx 0x2
simplebank-api-1 | ecx 0x8fabf6f
simplebank-api-1 | edx 0x17
simplebank-api-1 | edi 0x955cd6f
simplebank-api-1 | esi 0x9c003c0
simplebank-api-1 | ebp 0x98232c0
simplebank-api-1 | esp 0x9c4a630
simplebank-api-1 | eip 0x80a8242
simplebank-api-1 | eflags 0x206
simplebank-api-1 | cs 0x23
simplebank-api-1 | fs 0x0
simplebank-api-1 | gs 0x33
simplebank-api-1 exited with code 2
docker文件如下:
FROM golang:1.20-alpine3.16 AS builder
WORKDIR /app
COPY . .
RUN go build -o main main.go
RUN apk add curl
RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-386.tar.gz | tar xvz
#run
FROM alpine:3.16
WORKDIR /app
COPY --from=builder /app/main .
COPY --from=builder /app/migrate ./migrate
COPY app.env .
COPY start.sh .
COPY wait.sh .
COPY db/migration ./migration
EXPOSE 8080
CMD ["/app/main"]
ENTRYPOINT ["/app/start.sh"]
我的start.sh
#!/bin/sh
set -e
echo "run db migration "
/app/migrate -path /app/migration -database "$DB_SOURCE" -verbose up
echo "start the app"
exec "$@"
和docker-compose.yaml
version: "3.9"
services:
postgres:
image: postgres:15.2-alpine
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=simple_bank
api:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
- DB_SOURCE=postgresql://root:secret@postgres:5432/simple_bank?sslmode=disable
depends_on:
- postgres
entrypoint: ["/app/wait.sh","postgres:5432" , "--", "/app/start.sh"]
command: ["/app/main"]
1条答案
按热度按时间fykwrbwg1#
使用migrate.linux-amd64.tar.gz而不是migrate.linux-386.tar.gz