{"id":251,"date":"2025-04-06T10:53:23","date_gmt":"2025-04-06T08:53:23","guid":{"rendered":"https:\/\/www.24x7serverguard.com\/blog\/?p=251"},"modified":"2025-04-06T10:57:13","modified_gmt":"2025-04-06T08:57:13","slug":"if-youre-deploying-a-multi-container-app-via-cpanel-and-your-api-image-is-running-fine-but-it-needs-to-connect-to","status":"publish","type":"post","link":"https:\/\/www.24x7serverguard.com\/blog\/cpanel\/if-youre-deploying-a-multi-container-app-via-cpanel-and-your-api-image-is-running-fine-but-it-needs-to-connect-to\/","title":{"rendered":"If you&#8217;re deploying a multi-container app via cPanel, and your API image is running fine, but it needs to connect to:"},"content":{"rendered":"\n<ol class=\"wp-block-list\">\n<li>The <strong>Redis<\/strong> container (for caching or sessions),<\/li>\n\n\n\n<li>The <strong>Database<\/strong> container (e.g., MySQL\/PostgreSQL\/etc.)<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">To enable communication between your containers, especially when using <strong>cPanel<\/strong> (which might be using <strong>Docker<\/strong> or <strong>Podman<\/strong> under the hood), you need to make sure they are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On the same <strong>Docker network<\/strong><\/li>\n\n\n\n<li>Using the <strong>container name as hostname<\/strong> when calling each other<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Steps to ensure API can reach Redis and Database:<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>Use a custom bridge network<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This ensures containers can talk to each other by name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">docker network create app-network<\/mark><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>Run your containers on that network<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"># Redis<br>docker run -d --name redis --network app-network redis<br><br># Database (example: PostgreSQL)<br>docker run -d --name db --network app-network -e POSTGRES_PASSWORD=secret postgres<br><br># API<br>docker run -d --name api --network app-network your-api-image<\/mark><br><br>3. Update your API configuration<br>For Redis:<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">REDIS_HOST=redis<br>REDIS_PORT=6379<\/mark><br><br>For Database:<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">DB_HOST=db<br>DB_PORT=5432  # or 3306 for MySQL<\/mark><br><br>Make sure your API code uses environment variables (or hardcoded names) like redis and db as hostnames.<br><br>\ud83d\udee0 If you're using cPanel's GUI:<br>If you're not using SSH but managing containers through cPanel's Docker Manager or Application Manager, look for:<br><br>A way to assign the same network name to all containers.<br><br>Define environment variables for REDIS_HOST and DB_HOST.<br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To enable communication between your containers, especially when using cPanel (which might be using Docker or Podman under the hood), you need to make sure they are: \u2705 Steps to ensure API can reach Redis and Database: 1. Use a custom bridge network This ensures containers can talk to each other by name. docker network [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":253,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[197,199,202,198,200,201,203],"class_list":["post-251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","tag-api","tag-api-image-is-running-fine","tag-docker-network","tag-multi-container-app-via-cpanel","tag-mysql","tag-postgresql","tag-redis-host"],"_links":{"self":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":1,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/251\/revisions\/252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media\/253"}],"wp:attachment":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}