Run your docker images in order
Published 4 years and 9 months ago, Categorized under: docker, Linux, Nginx, Other

One of the many things that I found annoying in Docker (when you use docker-compose) is that you have no control over the order which the images is going to be up and running, in the documentation they have pointed out to three ways, am not going to cover them all, am just going to cover my experience with dockerize and how I used it to make sure that the database is up and running before I run the next image.

PS: please note that my way is not the best way, but it worked for me, and you should invest more time knowing and familiarize yourself with dockerize.

  1. Make sure that you install dockerize within the image which should be waiting for other images to finish

    RUN wget$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz   
       && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
  2. Make sure that your image does not have any service that run as daemon ( In my case it was NGINX )

  3. Make sure that your entrypoint should look like :

    entrypoint: dockerize -wait tcp://database:5432 kong start
  4. You will need to replace  tcp://database:5432 with the service and the port that you are waiting for, lets say for example tcp://nginx where we need to make sure that nginx is up and running on the default port 80.

  5. You will need to replace kong start with the service that you want to run, in my case it was Kong server.

You can look at this github repo where I created a small docker repo to run Kong and Postgresql out of the box

Share It via: