我有一个运行数据库迁移的容器(源):
FROM golang:1.12-alpine3.10 AS downloader
ARG VERSION
RUN apk add --no-cache git gcc musl-dev
WORKDIR /go/src/github.com/golang-migrate/migrate
COPY . ./
ENV GO111MODULE=on
ENV DATABASES="postgres mysql redshift cassandra spanner cockroachdb clickhouse mongodb sqlserver firebird"
ENV SOURCES="file go_bindata github github_ee aws_s3 google_cloud_storage godoc_vfs gitlab"
RUN go build -a -o build/migrate.linux-386 -ldflags="-s -w -X main.Version=${VERSION}" -tags "$DATABASES $SOURCES" ./cmd/migrate
FROM alpine:3.10
RUN apk add --no-cache ca-certificates
COPY --from=downloader /go/src/github.com/golang-migrate/migrate/build/migrate.linux-386 /migrate
ENTRYPOINT ["/migrate"]
CMD ["--help"]
我想将其集成到docker-compose中,并使其依赖于Postgres数据库服务。但是,由于必须等到数据库完全初始化后才能将migrate
命令包装在脚本中,因此需要替换迁移容器的入口点。我正在使用等待脚本来轮询数据库,这是一个纯shell(不是bash)脚本,因此应在高山容器中工作。
这是在docker-compose中定义服务的方式:
services:
database:
# ...
migration:
depends_on:
- database
image: migrate/migrate:v4.7.0
volumes:
- ./scripts/migrations:/migrations
- ./scripts/wait-for:/wait-for
entrypoint: ["/bin/sh"]
command: ["./wait-for database:5432", "--", "./migrate", "-path", "/migrations", "-database", "postgres://test:test@database:5432/test?sslmode=disable", "-verbose", "up"]
docker-compose up
在此运行失败
migration_1 | /bin/sh: can't open './wait-for database:5432': No such file or directory
使用本身运行迁移容器
docker run -it --entrypoint /bin/sh -v $(pwd)/scripts/wait-for:/wait-for migrate/migrate:v4.7.0
确实可以正常工作,脚本在那里并且可以与一起运行/bin/sh ./wait-for
。
那么,为什么它作为docker-compose的一部分失败了?
如果您仔细阅读错误消息,将会发现找不到的文件不是./waitfor
,而是./wait-for database:5432
。这与您的输入文件一致,其中整个内容作为command
列表的第一个元素给出:
command: ["./wait-for database:5432", "--", "./migrate", "-path", "/migrations", "-database", "postgres://test:test@database:5432/test?sslmode=disable", "-verbose", "up"]
我不清楚您实际想要的是什么,因为提出的可行替代方案似乎并不完全相似,但可能是
command: ["./wait-for", "database:5432", "--", "./migrate", "-path", "/migrations", "-database", "postgres://test:test@database:5432/test?sslmode=disable", "-verbose", "up"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句