<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Docker on WebDevStation</title>
    <link>https://webdevstation.com/tags/docker/</link>
    <description>1 article tagged Docker — tutorials, code examples and notes from building real systems, newest first.</description>
    <generator>Hugo</generator>
    <language>en</language>
    <managingEditor>Alex</managingEditor>
    <webMaster>Alex</webMaster>
    <copyright>© 2026 WebDevStation</copyright>
    <lastBuildDate>Tue, 05 Sep 2023 09:53:15 +0000</lastBuildDate>
    <atom:link href="https://webdevstation.com/tags/docker/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>One of The Easiest Ways to Host your Go Web App</title>
      <link>https://webdevstation.com/posts/one-of-thee-easiest-ways-to-host-go-web-apps/</link>
      <pubDate>Tue, 05 Sep 2023 09:53:15 +0000</pubDate>
      <author>Alex</author>
      <guid isPermaLink="true">https://webdevstation.com/posts/one-of-thee-easiest-ways-to-host-go-web-apps/</guid>
      <description>Discover how to host Go web applications for as little as $5 per month using DigitalOcean and Docker. Learn this cost-effective, scalable deployment method with…</description>
      <content:encoded><![CDATA[<p>Hello! In this post, I will explain the cost-effective method I use to host my Go web applications
with varying levels of complexity, all starting from as low as $5 per month. This method also allows to easy
deploy and scale your golang application.</p>
<p>As an example, this is how I host <a href="https://whattoreadafter.xyz" title="What to read after: AI book recommendations">whattoreadafter.xyz</a>, a service that recommends books based on the book you just finished reading, by using AI.</p>
<p>Starting off, let&rsquo;s enumerate the tools we&rsquo;ll be using alongside Golang:</p>
<ul>
<li><a href="https://m.do.co/c/2a29ebc23e4a">DigitalOcean</a> - a cloud computing platform that provides virtual machines and other resources.</li>
<li><a href="https://www.docker.com/">Docker</a> - a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.</li>
</ul>
<p>In order to follow along, you will need to have a DigitalOcean account. If you don&rsquo;t have one, you can
sign up <a href="https://m.do.co/c/2a29ebc23e4a">here</a> and get $200 in credit over 60 days.</p>
<p>Let&rsquo;s get started!
For simplicity sake, our application will be a simple web server that returns current time in UTC format.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#f92672">package</span> <span style="color:#a6e22e">main</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> (
</span></span><span style="display:flex;"><span>	<span style="color:#e6db74">&#34;fmt&#34;</span>
</span></span><span style="display:flex;"><span>	<span style="color:#e6db74">&#34;net/http&#34;</span>
</span></span><span style="display:flex;"><span>	<span style="color:#e6db74">&#34;time&#34;</span>
</span></span><span style="display:flex;"><span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">currentTimeHandler</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>) {
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">currentTime</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">time</span>.<span style="color:#a6e22e">Now</span>().<span style="color:#a6e22e">UTC</span>()
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Fprintf</span>(<span style="color:#a6e22e">w</span>, <span style="color:#e6db74">&#34;Current Time (UTC): %s&#34;</span>, <span style="color:#a6e22e">currentTime</span>.<span style="color:#a6e22e">Format</span>(<span style="color:#a6e22e">time</span>.<span style="color:#a6e22e">RFC3339</span>))
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">HandleFunc</span>(<span style="color:#e6db74">&#34;/&#34;</span>, <span style="color:#a6e22e">currentTimeHandler</span>)
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;Server is running on port 8080&#34;</span>)
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ListenAndServe</span>(<span style="color:#e6db74">&#34;:8080&#34;</span>, <span style="color:#66d9ef">nil</span>)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Now let&rsquo;s host it!</p>
<p>In order for you to easier follow along, I will list the steps we will take to host our application:</p>
<h2 id="1-prepare-a-dockerfile-for-our-application-and-place-it-in-the-root-of-our-project-alongside-the-maingo-file">1. Prepare a Dockerfile for our application and place it in the root of our project alongside the <code>main.go</code> file.</h2>
<p>Example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-dockerfile" data-lang="dockerfile"><span style="display:flex;"><span><span style="color:#66d9ef">FROM</span> <span style="color:#e6db74">golang:alpine</span> <span style="color:#66d9ef">AS</span> <span style="color:#e6db74">builder</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">RUN</span> apk add --no-cache --update <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>        git <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>        ca-certificates<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">ADD</span> . /app<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">WORKDIR</span> <span style="color:#e6db74">/app</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">COPY</span> go.mod ./<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">RUN</span>  go mod download<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">RUN</span> CGO_ENABLED<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> GOOS<span style="color:#f92672">=</span>linux GOARCH<span style="color:#f92672">=</span>amd64 go build -a -o /main .<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">FROM</span> <span style="color:#e6db74">alpine</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">COPY</span> --from<span style="color:#f92672">=</span>builder /main ./<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">RUN</span> chmod +x ./main<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">ENTRYPOINT</span> [<span style="color:#e6db74">&#34;./main&#34;</span>]<span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p> </p>
<h2 id="2-push-your-code-to-a-github-repository-you-can-make-it-private-if-you-want">2. Push your code to a GitHub repository. You can make it private if you want.</h2>
<p> </p>
<h2 id="3-go-to-digitalocean-and-create-a-new-app-you-can-do-so-by-clicking-on-the-apps-tab-in-the-left-sidebar-and-then-clicking-create-app">3. Go to <a href="https://cloud.digitalocean.com/apps">DigitalOcean</a> and create a new App. You can do so by clicking on the &ldquo;Apps&rdquo; tab in the left sidebar and then clicking &ldquo;Create App&rdquo;.</h2>
<p> </p>
<h2 id="4-select-github-as-your-source-and-click-continue">4. Select &ldquo;GitHub&rdquo; as your &ldquo;Source&rdquo; and click &ldquo;Continue&rdquo;.</h2>
<p><img src="/images/2023/do1.png" alt="Hosting Golang on digitalocean" title="Hosting Golang apps on digitalocean"></p>
<h2 id="5-select-the-repository-you-want-to-deploy-and-click-next">5. Select the repository you want to deploy and click &ldquo;Next&rdquo;.</h2>
<p><img src="/images/2023/do2.png" alt="Hosting Golang on digitalocean" title="Hosting Golang apps on digitalocean"></p>
<h2 id="6-select-dockerfile-as-your-build-type-and-click-next">6. Select &ldquo;Dockerfile&rdquo; as your &ldquo;Build type&rdquo; and click &ldquo;Next&rdquo;.</h2>
<p><img src="/images/2023/do3.png" alt="Hosting Golang on digitalocean" title="Hosting Golang apps on digitalocean"></p>
<h2 id="7-configure-environment-variables-if-you-need-to-and-click-next">7. Configure environment variables if you need to and click &ldquo;Next&rdquo;.</h2>
<p> </p>
<h2 id="8-select-region-for-your-app-and-click-next">8. Select region for your app and click &ldquo;Next&rdquo;.</h2>
<p><img src="/images/2023/do4.png" alt="Hosting Golang on digitalocean" title="Hosting Golang apps on digitalocean"></p>
<h2 id="9-in-the-billing-section-select-the-plan-you-want-to-use-you-can-start-with-the-5-per-month-plan-and-scale-up-later-if-you-need-to">9. In the billing section, select the plan you want to use. You can start with the $5 per month plan and scale up later if you need to.</h2>
<p><img src="/images/2023/do5.png" alt="Hosting Golang on digitalocean" title="Hosting Golang apps on digitalocean"></p>
<h2 id="10-click-create-resources-and-wait-for-your-app-to-be-deployed">10. Click &ldquo;Create Resources&rdquo; and wait for your app to be deployed.</h2>
<p> </p>
<h2 id="11-once-your-app-is-deployed-you-can-access-it-by-clicking-on-the-live-app-link">11. Once your app is deployed, you can access it by clicking on the &ldquo;Live App&rdquo; link.</h2>
<p><img src="/images/2023/do6.png" alt="Hosting Golang on digitalocean" title="Hosting Golang apps on digitalocean"></p>
<p>That&rsquo;s it! You have successfully deployed your Golang application!</p>
<p>You can also add your own domain name to your app by clicking on the &ldquo;Settings&rdquo; tab and then clicking on &ldquo;Domains&rdquo;.</p>
<p>Now, every time you push a new commit to your repository, DigitalOcean will automatically build and deploy your application.
This is a great way to host your Golang applications, especially if you are just starting out and don&rsquo;t want to spend a lot of money on hosting.</p>
<p>Thank you for reading! If you have any questions, feel free to reach out to me on <a href="https://twitter.com/oleks_i">Twitter</a>.</p>
<p>Before you point real traffic at it, two things are worth having in place: <a href="/posts/graceful-shutdown-in-go-web-services/">graceful shutdown</a>, so redeploys stop dropping requests, and <a href="/posts/an-easy-way-to-loadtest-your-web-apps/">a load test</a>, so you know what the box can actually take.</p>]]></content:encoded>
      <category>Go Programming</category>
      <category>DevOps</category>
      <category>Web Development</category>
    </item>
  </channel>
</rss>
