英文:
runnng migrations in postgres sql gives error:fatal: morestack on g0
问题
我正在尝试在我的Docker容器中运行迁移,并且在运行迁移命令时遇到以下错误:
当我在没有迁移命令的情况下运行docker compose up时,应用程序可以正常构建,我的数据库源是:
DB_SOURCE = "postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable"
我的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"]
请注意,我只提供了翻译的部分,不包括代码部分。
英文:
Im trying to run migration inside my docker container and im getting following error when trying to run migration command
when i run the docker compose up wihtout the migration command
/app/migrate -path /app/migration -database "$DB_SOURCE" -verbose up
the app builds fine and my DB SOURCE is
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
my docker file is following :
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"]
my start.sh is
#!/bin/sh
set -e
echo "run db migration "
/app/migrate -path /app/migration -database "$DB_SOURCE" -verbose up
echo "start the app"
exec "$@"
and docker-compose.yaml is following
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
得分: 0
请使用 migrate.linux-amd64.tar.gz 替代 migrate.linux-386.tar.gz。
英文:
use migrate.linux-amd64.tar.gz instead of
migrate.linux-386.tar.gz
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论