Docker Community Forums

Share and learn in the Docker community.

Communicating with the database container on build


(Vanderkerkoff) #1

Hello there

Does anyone have any links on how I manage running commands from a ruby container, to a mysql container, all in one stack, during deploy?

the commands I need to run are along these lines

rails db:migrate

I can’t work out where to put those types of commands.

If I put them into the Dockerfile for the ruby image, then if the database image isn’t up, they will fail.

Do these sorts of commands go into docker-cloud.yml, or do I need to call a .sh script in my Dockerfile to do them, after waiting for a connection from the DB to get setup?

I’m kind of talking about post deploy hooks I suppose.

Any tips or links greatly appreciated.


(Czechjiri) #2

you can use simply loop in your app startup script container and wait for DB

  1. probe DB port - there is utility https://github.com/vishnubob/wait-for-it for this
  2. use database native CLI to probe DB

I use pg_isready for postgres (mySQL probably has similar thing) here is my sample https://gist.github.com/CzechJiri/29c9862393c6a9d4435a2bfd50cf546d


(Vanderkerkoff) #3

Cheers dude, exactly what I needed.