migrate icon indicating copy to clipboard operation
migrate copied to clipboard

Got 'error: EOF' when running migrate command in shell script after 'docker run'

Open fahrinh opened this issue 5 years ago • 4 comments

Describe the Bug I want to run migrate in shell script (resetdb.sh) like this:

#!/usr/bin/env bash

docker rm sync-backend-db --force
docker run --name sync-backend-db -e POSTGRES_PASSWORD=dbpass123 -e POSTGRES_DB=sync_backend_db -d -p 5432:5432 postgres:12.2

migrate -verbose -source "file://db/migrations" -database 'postgres://postgres:dbpass123@localhost:5432/sync_backend_db?sslmode=disable' up

Running it got an error error: EOF. BUT if I comment out these two docker commands (docker rm ... & docker run ...), it is working as intended.

Steps to Reproduce Steps to reproduce the behavior:

$ ./resetdb.sh
sync-backend-db
6a01e52a7fd71886bef080043cd445ccbb474764f727df389f7f97cd3441d515
2020/03/31 09:25:00 error: EOF

Expected Behavior Shell script running without errors

Migrate Version I use asdf

$ GO111MODULE=off go get -tags 'postgres' -u -v github.com/golang-migrate/migrate/cmd/migrate
$ asdf reshim golang
$ migrate -version
dev

Loaded Source & Database Drivers

$ migrate -help
...
Source drivers: file
Database drivers: stub, postgres, postgresql

Go Version

$ go version
go version go1.14.1 darwin/amd64

fahrinh avatar Mar 31 '20 02:03 fahrinh

Sorry for the delayed response. What do your migrations look like? Does your output above include migrate's verbose log output?

dhui avatar Sep 14 '20 05:09 dhui

II am also getting the EOF error on macOS.

$ migrate -verbose -source file://./migrations -database "postgresql://admin:pass@localhost:5432/dev?sslmode=disable" up
2021/09/23 17:26:03 error: EOF

hexcowboy avatar Sep 23 '21 22:09 hexcowboy

Yeah I'm also getting this issue for some reason.

jeffk1m avatar Mar 31 '22 02:03 jeffk1m

You should make sure that PostgreSQL is ready to accept connections before running migrations. This can be done using pg_isready:

for i in {1..10}; do docker exec <container_name> pg_isready && break || sleep 1; done

aemdemir avatar Oct 23 '22 22:10 aemdemir