Skip to content
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

production migrate command #22

Open
oppianmatt opened this issue Apr 13, 2016 · 6 comments
Open

production migrate command #22

oppianmatt opened this issue Apr 13, 2016 · 6 comments

Comments

@oppianmatt
Copy link

In your guide you have:

$ docker-compose build
$ docker-compose -f production.yml up -d
$ docker-compose run web /usr/local/bin/python manage.py migrate

But shouldn't that be?

$ docker-compose -f production.yml build
$ docker-compose -f production.yml run web python -u manage.py migrate
$ docker-compose -f production.yml up -d

Needs to specify the file each time. And migrate should run before up incase there are migrations to run.

@mjhea0
Copy link
Contributor

mjhea0 commented Apr 18, 2016

You would at least need to get Postgres up before running the migrations if you handle it that way.

@mjhea0 mjhea0 closed this as completed Apr 18, 2016
@oppianmatt
Copy link
Author

With the links in compose it will start the postgres container when you run the web container to do the migrate.

If you don't do the migrate first AND there are new migrations it might error on startup until you run migrate. For example if you have pulled new migrations down from in a team.

@mjhea0
Copy link
Contributor

mjhea0 commented Apr 26, 2016

Your suggestion is to remove the links and then run the commands in this order? @oppianmatt

$ docker-compose -f production.yml build
$ docker-compose -f production.yml run web python -u manage.py migrate
$ docker-compose -f production.yml up -d

@mjhea0 mjhea0 reopened this Apr 26, 2016
@oppianmatt
Copy link
Author

no keep the links but do the run migrate first. It will start up postgres as needed and apply any migrations that might be in the source and not in the db.

@mjhea0
Copy link
Contributor

mjhea0 commented Apr 26, 2016

I believe Docker is removing links altogether in the next release. May be worth removing them now. Also the DB would have to be up, so the commands would need to be:

$ docker-compose -f production.yml build
$ docker-compose -f production.yml up postgres -d
$ docker-compose -f production.yml run web python -u manage.py migrate
$ docker-compose -f production.yml up -d

@oppianmatt
Copy link
Author

Where did you see docker-compose is removing links?

docker is removing legacy container links https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

I believe links are still there, just now with the network. On the docker-compose links reference page:

Links also express dependency between services in the same way as depends_on, so they determine the order of service startup.

Note: If you define both links and networks, services with links between them must share at least one network in common in order to communicate.

So links is still used, and used to determine startup order. So if web links to postgres then running web will also start postgres first.

# built the containers if needed
$ docker-compose -f production.yml build
# migrate if needed, will automatically start postgres, run this if pulling new migrations down
$ docker-compose -f production.yml run web python -u manage.py migrate
# start up anything that hasn't already started
$ docker-compose -f production.yml up -d

Note if postgres is restart always, it will be started anyway.

For windows/mac users the migrate command needs to be:

# windows/mac users have to run in detach mode
$ docker-compose -f production.yml run -d web python -u manage.py migrate --noinput
# but you can still monitor progress
$ docker-compose logs <containername>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants