<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Clarence Bakosi - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Clarence Bakosi - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 12 Jun 2026 05:19:20 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/ogenieni/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Move a Single Fly Machine and Volume to a New Region with flyctl ]]>
                </title>
                <description>
                    <![CDATA[ Fly.io allows users to deploy their applications to virtual machines in regions where their applications are mostly used. A Fly application can also be deployed to multiple regions. You may want to move your Fly application to a new region if you exp... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-move-a-fly-application-to-a-new-region/</link>
                <guid isPermaLink="false">66bb4ce074045df86842bf26</guid>
                
                    <category>
                        <![CDATA[ Cloud ]]>
                    </category>
                
                    <category>
                        <![CDATA[ deployment ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Clarence Bakosi ]]>
                </dc:creator>
                <pubDate>Thu, 18 Jul 2024 13:19:23 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/07/Cover-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Fly.io allows users to deploy their applications to virtual machines in regions where their applications are mostly used. A Fly application can also be deployed to multiple regions.</p>
<p>You may want to move your Fly application to a new region if you experience performance issues, high latency, or data residency compliance problems. Placing your application closer to your users can reduce latency and improve response time.</p>
<p>Additionally, aligning your data storage with regional compliance requirements can prevent legal issues. Overall, these changes enhance the user experience with your application.</p>
<p>This article will cover how to smoothly move a Fly application that includes a single <a target="_blank" href="https://fly.io/docs/machines/overview/">Fly Machine</a> and an attached <a target="_blank" href="https://fly.io/docs/volumes/overview/">Fly Volume</a>, from one <a target="_blank" href="https://fly.io/docs/reference/regions/">Fly region</a> to another using <a target="_blank" href="https://fly.io/docs/flyctl/">flyctl</a> commands.</p>
<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<ul>
<li><a target="_blank" href="https://fly.io/dashboard">Fly.io account</a></li>
<li><code>flyctl</code> installed</li>
<li>Command line Interface (CLI)</li>
</ul>
<h2 id="heading-getting-started"><strong>Getting Started</strong></h2>
<p>To get started, you will have to verify if you already have <code>flyctl</code> installed and also get it authenticated.</p>
<h3 id="heading-how-to-verify-flyctl-installation">How to Verify <code>flyctl</code> Installation</h3>
<p>You can verify that you have <code>flyctl</code> installed using the command below. If not, use this <a target="_blank" href="https://fly.io/docs/flyctl/install/">guide</a> to install it.</p>
<pre><code class="lang-bash">fly version
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-19.43.16.png" alt="fly version" width="600" height="400" loading="lazy">
<em>Output of fly version</em></p>
<p>This shows the version you have installed.</p>
<h3 id="heading-how-to-authenticate-flyctl">How to Authenticate <code>flyctl</code></h3>
<p>Connect the terminal to your account via the CLI using:</p>
<pre><code class="lang-bash">fly auth login
</code></pre>
<p>When the browser opens up, login if you aren't already logged in and proceed to authenticate your CLI.</p>
<p>After authenticating your account, return to the CLI.</p>
<h2 id="heading-how-to-confirm-the-region-of-the-application"><strong>How to Confirm the Region of the Application</strong></h2>
<p>Navigate to the root folder of your project and run the following to determine the current region of your application:</p>
<pre><code class="lang-bash">fly status
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-19.44.26.png" alt="fly status" width="600" height="400" loading="lazy">
<em>Output of fly status</em></p>
<p>The application's current region is <code>lhr</code>, the command shows additional information about the application, including the app name, owner, hostname, image, and machine details.</p>
<h2 id="heading-how-to-verify-the-number-of-volumes-available"><strong>How to Verify the Number of Volumes Available</strong></h2>
<p>Run the following command to list all volumes:</p>
<pre><code class="lang-bash">fly volumes list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-19.45.05.png" alt="fly volumes list" width="600" height="400" loading="lazy">
<em>Output of fly volumes list</em></p>
<p>There should be only one volume that exists and it should be already attached to a machine. You can use this <a target="_blank" href="https://fly.io/docs/apps/volume-storage/#launch-a-new-app-with-a-fly-volume">guide</a> to create an application with a single machine with an attached volume.</p>
<h2 id="heading-how-to-verify-that-the-volume-is-attached-to-a-machine"><strong>How to Verify that the Volume is Attached to a Machine</strong></h2>
<p>To ensure the volume is attached to a machine, run:</p>
<pre><code class="lang-bash">fly machine list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.14.04.png" alt="fly machine list" width="600" height="400" loading="lazy">
<em>Output of fly machine list</em></p>
<p>From the output, you can determine if there is a volume attached to the machine.</p>
<h2 id="heading-list-of-fly-regions"><strong>List of Fly Regions</strong></h2>
<p>To determine the new region you want to move the Machine and volume to, use the following command to view the list of available regions:</p>
<pre><code class="lang-bash">fly platform regions
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.15.13.png" alt="fly platform regions" width="600" height="400" loading="lazy">
<em>Output of fly platform regions</em></p>
<p>For this article, the machine and volume will be moved to the <code>syd</code> region.</p>
<h2 id="heading-fork-the-available-volume-to-a-new-region"><strong>Fork the Available Volume to a New Region</strong></h2>
<p>You can create a copy of an existing volume and place it into a new region by forking it using the current volume ID to create a fork:</p>
<pre><code class="lang-bash">fly volumes fork vol_4yj0k93z118j9x14 --region syd
</code></pre>
<p>Result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.16.00.png" alt="fly volumes fork" width="600" height="400" loading="lazy">
<em>Output of fly volumes fork</em></p>
<p>This shows information about the newly created volume.</p>
<pre><code class="lang-bash">fly volumes list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.18.52.png" alt="fly volumes list" width="600" height="400" loading="lazy">
<em>Output of fly volumes list</em></p>
<p>The current state of the new forked volume in a new region will be in a <code>hydrating</code> state for a couple of minutes before it is changed to <code>created</code>.</p>
<pre><code class="lang-bash">fly volumes list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.19.11.png" alt="fly volumes list" width="600" height="400" loading="lazy">
<em>Output of fly volumes list</em></p>
<p>The image above shows current state after <code>hydrating</code> is complete.</p>
<p>You have successfully created a new volume in another region containing data from the volume existing in the old region.</p>
<h2 id="heading-how-to-clone-the-existing-machine"><strong>How to Clone the Existing Machine</strong></h2>
<p>Fly possesses the clone feature to replicate a machine and you can make use of this by getting the ID of the existing machine.</p>
<pre><code class="lang-bash">fly machine list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.19.43.png" alt="fly machine list" width="600" height="400" loading="lazy">
<em>Output of fly machine list</em></p>
<p>After retrieving the ID of the machine, use the command below to clone the machine and attach the new volume using the same region as the newly created volume:</p>
<p>For example:</p>
<pre><code class="lang-bash">fly machine <span class="hljs-built_in">clone</span> &lt;machine id&gt; --region &lt;region code&gt; --attach-volume &lt;volume id&gt;:&lt;destination_mount_path&gt;
</code></pre>
<p>It's important to note that the <code>destination_mount_path</code> has to be a different path other than <code>/</code> which is the root directory of the application. It should be a unique path <code>/zata</code>.</p>
<pre><code class="lang-bash">fly machine <span class="hljs-built_in">clone</span> 5683977a624218 --region syd --attach-volume vol_vzkd2l6yxnk72p9v:/zata
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.20.06.png" alt="fly machine clone" width="600" height="400" loading="lazy">
<em>Output of fly machine clone</em></p>
<p>You have successfully created a clone of the existing machine and attached the forked volume.</p>
<h2 id="heading-how-to-verify-the-volume-attachment"><strong>How to Verify the Volume Attachment</strong></h2>
<p>To check if the volume has been successfully attached:</p>
<pre><code class="lang-bash">fly volumes list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.20.37.png" alt="fly volumes list" width="600" height="400" loading="lazy">
<em>Output of fly volumes list</em></p>
<p>The volume is now attached to a machine.</p>
<p>To check if the machine has been successfully attached:</p>
<pre><code class="lang-bash">fly machine list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.21.08.png" alt="fly machine list" width="600" height="400" loading="lazy">
<em>Output of fly machine list</em></p>
<p>The machine now has a volume attached.</p>
<p>You have successfully moved the machine and volume to a new region.</p>
<h2 id="heading-how-to-view-the-application-available-regions"><strong>How to View the Application Available Regions</strong></h2>
<p>Currently, the application exists in two different regions and you can view this using the following command:</p>
<pre><code class="lang-bash">fly scale show
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.21.30.png" alt="fly scale show" width="600" height="400" loading="lazy">
<em>Output of fly scale show</em></p>
<p>The application is now running in <code>lhr</code> and <code>syd</code>.</p>
<h2 id="heading-how-to-update-the-remote-flytoml"><strong>How to Update the Remote fly.toml</strong></h2>
<p>Add the new region to the <strong>fly.toml</strong> file <code>primary_region = 'syd'</code>, update the volume destination to <code>destination = '/zata'</code>, and deploy the changes.</p>
<pre><code class="lang-bash">fly deploy
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.22.37.png" alt="fly deploy" width="600" height="400" loading="lazy">
<em>Output of fly deploy</em></p>
<p>Once this is successful, the changes to the <strong>fly.toml</strong> file will be on the remote configuration.</p>
<h2 id="heading-how-to-destroy-the-old-machine"><strong>How to Destroy the Old Machine</strong></h2>
<p>You have successfully moved your machine and attached volume to a new region and since we no longer need the machine in the old region <code>lhr</code>, you will have to clean it up. The first approach is to stop the machine using the ID.</p>
<h3 id="heading-stop-the-old-machine">Stop the Old Machine</h3>
<pre><code class="lang-bash">fly machine stop &lt;old_machine_id&gt;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.23.39.png" alt="fly machine stop" width="600" height="400" loading="lazy">
<em>Output of fly machine stop</em></p>
<p>To confirm if it was successful, use:</p>
<pre><code class="lang-bash">fly machine list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.24.11.png" alt="fly machine list" width="600" height="400" loading="lazy">
<em>Output of fly machine list</em></p>
<p>The state of the machine has been updated to <code>stopped</code></p>
<h3 id="heading-destroy-the-old-machine">Destroy the Old Machine</h3>
<pre><code class="lang-bash">fly machine destroy &lt;old_machine_id&gt;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.24.35.png" alt="fly machine destroy" width="600" height="400" loading="lazy">
<em>Output of fly machine destroy</em></p>
<p>Run the below command to verify if the machine still exists.</p>
<pre><code class="lang-bash">fly machine list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.24.59.png" alt="fly machine list" width="600" height="400" loading="lazy">
<em>Output of fly machine list</em></p>
<p>The machine in the old region has been successfully deleted.</p>
<h2 id="heading-how-to-destroy-the-unattached-volume"><strong>How to Destroy the Unattached Volume</strong></h2>
<p>After successfully destroying the Machine, the volume attached to it is now unattached and can also be destroyed.</p>
<pre><code class="lang-bash">fly volumes list
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.25.24.png" alt="fly volumes list" width="600" height="400" loading="lazy">
<em>Output of fly volumes list</em></p>
<p>Use the ID of the unattached volume and run the below command:</p>
<pre><code class="lang-bash">fly volumes destroy &lt;old_volume_id&gt;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.26.04.png" alt="fly volumes destroy" width="600" height="400" loading="lazy">
<em>Output of fly volumes destroy</em></p>
<p>The unattached volume has now been destroyed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/Screenshot-2024-07-15-at-20.26.27.png" alt="fly volumes list" width="600" height="400" loading="lazy">
<em>Output of fly volumes list</em></p>
<p>Only one volume exists and is attached to a machine in the new region.</p>
<h2 id="heading-how-to-check-the-state-of-the-instance"><strong>How to Check the State of the Instance</strong></h2>
<p>Check the logs to see the state of the instance:</p>
<pre><code class="lang-bash">fly logs
</code></pre>
<p>The logs show the application is running without any issues.</p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Moving a Fly.io application to a new region involves forking the existing volume, cloning the existing machine with the forked volume to a new region, updating <strong>fly.toml</strong>, deploying the changes, and removing the old machine and volume. </p>
<p>Following these guidelines ensures a smooth and successful transition with minimal disruption.</p>
<p> If you have any questions you can always find me on <a target="_blank" href="https://x.com/X8inez">X (formerly Twitter)</a></p>
<h2 id="heading-resources"><strong>Resources</strong>:</h2>
<ul>
<li><a target="_blank" href="https://fly.io/docs">Fly Docs</a></li>
<li><a target="_blank" href="https://fly.io/docs/flyctl">Flyctl</a></li>
<li><a target="_blank" href="https://fly.io/docs/machines/overview/">Fly Machines</a></li>
<li><a target="_blank" href="https://fly.io/docs/volumes/overview/">Fly Volumes</a></li>
<li><a target="_blank" href="https://fly.io/docs/reference/regions/">Fly regions</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
