<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Albert Oketch on Medium]]></title>
        <description><![CDATA[Stories by Albert Oketch on Medium]]></description>
        <link>https://medium.com/@albertoketch?source=rss-badf5b8154ee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Big7uZz0KdRaMnA_.</url>
            <title>Stories by Albert Oketch on Medium</title>
            <link>https://medium.com/@albertoketch?source=rss-badf5b8154ee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:09:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@albertoketch/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hosting A TCP Server on Google Compute Engine]]></title>
            <link>https://albertoketch.medium.com/hosting-a-tcp-server-on-google-compute-engine-93748e08631?source=rss-badf5b8154ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/93748e08631</guid>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Albert Oketch]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 09:05:35 GMT</pubDate>
            <atom:updated>2021-02-08T09:05:35.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*60WSDXziBSayTVMrL6ROyw.png" /></figure><p>In this article we will be going through deploying a TCP server on GCE. The server will be built using Node.js. We will also containerise the server using Docker.</p><p><a href="https://cloud.google.com/compute/">Google Compute Engine</a>(GCE) is IaaS(Infrastructure as a Service) offered on Google Cloud Platform(GCP). Users are able to provision virtual machines(VM’s) which will run on Google’s physical infrastructure. There can be many different configurations for GCE VM’s. We will use a <a href="https://cloud.google.com/container-optimized-os/">Container-Optimized OS</a> for our server, which is a VM optimised for running Docker containers.</p><h4>Setting Up the Server Code</h4><p>Using Node.js we will set up a server which will accept TCP connections and then we will simply log to our console and close the TCP connection.</p><p>We will start with a simple index.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52c87b6f709aef1b60f7a40195d0a8ca/href">https://medium.com/media/52c87b6f709aef1b60f7a40195d0a8ca/href</a></iframe><p>Now that we have our node tcp server set up, we can add a docker configuration file to be able to containerise our tcp server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dd57480879dfcaf99680001c3f77fa1/href">https://medium.com/media/1dd57480879dfcaf99680001c3f77fa1/href</a></iframe><h4>Building The Docker Image</h4><p><a href="https://docs.docker.com/">Docker</a> will help with bundling the app into a container. This makes it easier to deploy an application with all its dependencies as one package.</p><p>To build the docker image, in the terminal/command line, we will run this command:</p><pre>docker build . -t gcr.io/${PROJECT_ID}/node-tcp:latest</pre><p>This will create a docker image tagged <em>latest</em>. After this we can push the image to Google Cloud Image Registry:</p><pre>gcloud docker -- push gcr.io/${PROJECT_ID}/node-tcp:latest</pre><p>Or with <a href="https://cloud.google.com/sdk/gcloud/reference/auth/configure-docker">gcloud docker configured,</a> simply:</p><pre>docker push gcr.io/${PROJECT_ID}/node-tcp:latest</pre><p>Now we can move to the next step which is setting up the Compute Engine instance on GCP.</p><h4>Setting up GCE</h4><p>In order to create a Compute Engine instance we will have to create a new project. To do this we will get onto the GCP <a href="https://console.cloud.google.com/">console</a> then, in the top left corner, after the text Google Cloud Platform, select the dropdown and click <em>New Project</em>. Give your project a name then click create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_xgIN65HUICYzLKRubc7g.png" /><figcaption>Select dropdown</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gPsSm5wR_t3iLHcevJCzaA.png" /><figcaption>Select “NEW PROJECT”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YC2YE0ZlA8pFcEjouDi3lg.png" /><figcaption>Give your project a name and click “CREATE”</figcaption></figure><p>Once that is complete, click on the hamburger menu on the top left and select the Compute Engine option in the menu. Select create to begin setting up the VM instance. If you already have an existing VM select <em>Create Instance </em>in the top menu. Then we will define the settings/configuration for the Compute Engine VM instance.</p><p>First, give the instance a name; this could be a unique name or use the default value. Next is the machine configuration. Under series choose N1 and in the machine type dropdown, choose f1-micro. The server doesn’t need much memory and the compute power is low, making this a good choice for the tcp server.</p><p>After configuring the machine type, select “<em>Deploy a container image to this VM instance”. </em>In the <em>Container image </em>text box, paste the image pushed above, that is, gcr.io/${PROJECT_ID}/node-tcp:latest . This will create a VM instance which, on startup, will pull the image and run the containerised application on the VM.</p><p>Finally click create and wait for the container to be provisioned. The next image shows the layout of the configuration we have just gone through.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*nTIavbSS1HBxoNJ4k5lHfw.png" /><figcaption>VM Configuration</figcaption></figure><h4>Connecting to the Server</h4><p>Once the compute engine instance has been created, in the GCE VM instances page, copy the external ip address. This will be used to make requests to the TCP server.</p><p>Congratulations, you’ve deployed a server on GCP!</p><blockquote>PS: Remember to delete (shutdown) the project if this was an experimental run at <a href="https://console.cloud.google.com/iam-admin/settings?project=tcp-node-server">https://console.cloud.google.com/iam-admin/settings?project=</a>${YOUR_PROJECT_ID}</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93748e08631" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>