This image allows you to run your Goose migrations from a Docker container.
-
Create a
Dockerfile
in the directory that has yourdbconf.yml
- TIP: Your
dbconf.yml
is a lot more useful if it uses environment variables that you can set when you run the migration. For example, this should work for any postgres installation:default: driver: postgres open: $DATABASE_URL
- TIP: Your
-
Your
Dockerfile
should containFROM cstroe/docker-goose:latest
. Most won't need anything more. -
Build and run your new container. The Docker engine will
ADD
yourdbconf.yml
and migrations directory using the ONBUILD triggers, then executegoose up
. You can pass a command to execute something other thanup
.
The following environment variables can be passed to the container:
GOOSE_ENV
- customizes the goose-env
flag value. Defaults todefault
.DEBUG
- if this environment variable is defined, print values of environment variables.
Given a project with a db
directory at the root of the project containing SQL migration scripts and the following dbconf.yml
:
myenv:
driver: mysql
open: myuser:mypass@tcp(${DB_URL})/mydb
And the following Dockerfile-goose
:
FROM cstroe/docker-goose:latest
And a docker-compose.yml
file similar to this:
version: "2.4"
services:
db:
<... your database container here ...>
goose:
build:
dockerfile: ./Dockerfile-goose
context: .
environment:
DATABASE_URL: db:3306
GOOSE_ENV: myenv
depends_on:
db:
condition: service_healthy
Then run:
docker-compose up -d --build
That will start the database and run the migrations.
- Goose database migration library on BitBucket.
- Forked from JustinTulloss/docker-goose.
- Inspired from shopkeep/goose.
- pressly/goose - a fork of Goose with more features