Categories: BlogCanonicalUbuntu

Deploy Container on Ubuntu Pro on Google Cloud

Since I wrote Launch Ubuntu Desktop on Google Cloud last week, I kept thinking about putting Ubuntu Desktop into containers. A container is an independent unit of software packages and their dependencies so that the application on the container can run reliably in different computing environments. Docker, an open-source project launched in 2013, made Container technology popular all over the world in just a few years. Why? Let’s compare Containers and Virtual Machines.

Sponsored

The fundamental difference between Virtual Machine and Container is that Containers do not contain a guest Operating System. Containers virtualize the operating system instead of hardware, hence are more portable and efficient. Multiple containers can run on the same machine and share the same OS kernel with other containers. That being said, Containers are much smaller than VMs. You can run 4-6 times as many containers as VMs in the same physical machine.

However, Docker didn’t invent Container, instead, Docker built its technology base on LXC, a method of containerization developed by Canonical in 2008.

In this tutorial, we will create a Docker Container on the latest Ubuntu Pro 20.04 by following 3 steps:

  1. Launch a Ubuntu VM instance on Google Cloud to host Containers.
  2. Install Docker.
  3. Pull a Docker Image and run the container.

Launch a Ubuntu VM to host Containers

In this step, we will launch a VM instance in Google Cloud. The default e2-medium (2 vCPU, 4 GB memory) machine type works fine for the tutorial purpose. If you want a more performant machine, there are a variety of choices in Google Cloud.

1. In the Google Cloud Console, go to the VM Instances page:

2. Click CREATE INSTANCE.

3. Set the instance name to ubuntu-container-host .

4. Select a region and zone you want to run your instance.

5. Scroll down to the Boot disk options and click Change

6. In the Boot disk pop-up window, in Operating System, select Ubuntu Pro from the drop-down; in Version, select Ubuntu-Pro-20.04-LTS; keep the rest options as default value and click SELECT. Ubuntu Pro ensures the latest security update, which will be useful when we install the productivity applications.

7. Click CREATE to create the instance.

8. In less than one minute, you will be able to see your Ubuntu instance in RUNNING status. You can click the SSH button in the instance list to connect to your new instance.

If you prefer to start a VM through Google Cloud Shell, you can use this command to achieve the same result:

gcloud compute instances create ubuntu-container-host --zone=us-central1-a --machine-type=e2-medium --image=projects/ubuntu-os-pro-cloud/global/images/ubuntu-pro-2004-focal-v20210720

Install Docker

In Ubuntu, the easiest way to install Docker is to snap. A snap is a bundle of an app and its dependencies that works without modification across many different Linux distributions. Snaps are discoverable and installable from the Snap Store, an app store with an audience of millions.

1. In the SSH window connected to your VM instance, update the package manager data and install Docker

Sponsored
sudo apt update
sudo snap install docker

That’s it! Snap makes installation so easy.

Pull a Docker Image and run the container

Let’s first search for ubuntu images.

sudo docker search ubuntu

We found a lot of ubuntu related images:

NAME                                                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   13254     [OK]     
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   590                  [OK]
websphere-liberty                                         WebSphere Liberty multi-architecture images …   282       [OK]       

[OK] means that the image was built and supported by a company. We will pull the latest official Ubuntu Image

sudo docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete 
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

Check the images we downloaded to this VM instance:

sudo docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    ba6acccedd29   7 weeks ago   72.8MB

Let’s run a container based on this official Ubuntu image.

sudo docker run -it ubuntu
root@81046dba57f4:/#

In this container, we can check if it is the latest version of ubuntu:

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"

Yes, it is the latest version. Let’s install python into this container.

apt update
apt install python3

Check the version we installed:

/usr/bin/python3 -V
Python 3.8.10

Since we modify the original Ubuntu image, we want to save the changes to new images. We click “Ctrl + P” and “Ctrl + Q” to exit the container interface and back the VM.

sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED          STATUS          PORTS     NAMES
81046dba57f4   ubuntu    "bash"    21 minutes ago   Up 21 minutes             bold_sammet

We commit the changes to a new Docker image:

sudo docker commit -m "installed python3" -a "hugo" 81046dba57f4

-m with parameter “installed python3″ indicates the changes made to this image.

-a with parameter “hugo” indicates that I am the author of these changes.

sudo docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
           2316816463ea   16 seconds ago   144MB
ubuntu       latest    ba6acccedd29   7 weeks ago      72.8MB

That’s it. We made a Docker Container Image on Ubuntu Pro on Google Cloud.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

4 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

6 days ago