{"id":14090,"date":"2022-10-03T14:20:07","date_gmt":"2022-10-03T14:20:07","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=14090"},"modified":"2025-07-12T05:40:16","modified_gmt":"2025-07-12T05:40:16","slug":"docker-compose-wait-for-container-one-before-starting-container-second","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/docker-compose-wait-for-container-one-before-starting-container-second\/","title":{"rendered":"Docker Compose Tutorials: Wait for container one before starting container second"},"content":{"rendered":"\n<p><strong>Reference<\/strong><br>https:\/\/stackoverflow.com\/questions\/31746182\/docker-compose-wait-for-container-x-before-starting-y<\/p>\n\n\n\n<p><strong>Questions<\/strong><br>I am using rabbitmq and a simple python sample from here together with docker-compose. My problem is that I need to wait for rabbitmq to fully started. From what I searched so far, I don&#8217;t know how to wait with container x ( in my case worker ) until y (rabbitmq) is started.<\/p>\n\n\n\n<p><strong>Answer<\/strong><\/p>\n\n\n\n<p>Since docker-compose file format 2.1 you can define healthchecks.<\/p>\n\n\n\n<p>Now I test if the management page of the rabbitmq-container is available. If curl finishes with exitcode 0 the container app (python pika) will be started and publish a message to hello queue. Its now working (output).<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/15b8d07febc94a014968f2b2264ef9cd.js\"><\/script>\n\n\n\n<p>Docker Tutorials Fundamental To Advanced-2021 Crash Course:- <a href=\"https:\/\/bit.ly\/3hOIbTB\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/bit.ly\/3hOIbTB<\/a><\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_83333\"><iframe loading=\"lazy\"  id=\"_ytid_59538\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_83333\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Referencehttps:\/\/stackoverflow.com\/questions\/31746182\/docker-compose-wait-for-container-x-before-starting-y QuestionsI am using rabbitmq and a simple python sample from here together with docker-compose. My problem is that I need to wait for rabbitmq to fully started. From what&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4862,1],"tags":[],"class_list":["post-14090","post","type-post","status-publish","format-standard","hentry","category-docker","category-sql"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/14090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=14090"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/14090\/revisions"}],"predecessor-version":[{"id":31436,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/14090\/revisions\/31436"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=14090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=14090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=14090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}