-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invoke dbmate from Docker and trigger migration in postgres #128
Comments
In fact forget about another Docker container, it fails to connect to the postgres on the host as well, with the same error. |
By default docker containers have their own network and IP address. There are several ways you can work around this. If you're running postgres on your local computer you should be able to connect to it by running the dbmate container with host networking (I'll add this to the readme): docker run --rm --network=host -it amacneil/dbmate If you're running postgres in another container, again there are several ways to solve this. One option is to expose the port from the postgres container to your host (using docker run --rm -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres
docker run --rm -it --network=host -e DATABASE_URL="postgres://postgres:postgres@localhost/foo?sslmode=disable" amacneil/dbmate create Another is to put both the postgres container and dbmate on a private container network (and not expose them to the host): docker network create mynet
docker run --rm -d -e POSTGRES_PASSWORD=postgres --name=pg --network=mynet postgres
docker run --rm --network=mynet -e DATABASE_URL="postgres://postgres:postgres@pg/foo?sslmode=disable" amacneil/dbmate create Finally, you can also do this using docker compose by adding |
@amacneil thanks for taking your time to clarify this. Would have been great to have this somewhere in readme. |
Thanks for the feedback - I updated the readme. |
I was trying the following:
However I repeatedly get:
DATABASE_URL
points to the postgres server running on another Docker container (not sure how that should matter?)Do I need to to anything in addition to the above command to be able to run migrations on another Docker container that is running postgres?
The text was updated successfully, but these errors were encountered: