How to Start up an Ubuntu Container by using Docker

How to Start up an Ubuntu Container by using Docker

Overview

This tutorial is a guide on how to start up a Docker Container that runs Ubuntu.

Materials

  • Docker or Docker Desktop

  • Dockerhub (Optional) - To visit Docker and to download the software, there are instructions on the official Docker website for all operating systems: https://www.docker.com/

What is Docker?

Docker is software that creates containers. Containers are built to run fully developed applications that could be shared and run on other computers. For example, if one computer contains the source code for a Word Generator application, it could be distributed through other computers by first converting the source code into an image and running it to make a container to access the application. It is optional the image can be published to Dockerhub, where other computers can download the image and run it. Dockerhub is a place where pre-existing Docker images exist, and this tutorial will demonstrate how to download the official Ubuntu image and run it. To visit Dockerhub and see many pre-existing images, please visit the official website: https://hub.docker.com/

On the top-left of the screen, an image can be searched by using the search bar

To navigate the entire image list, scroll down and click on "See all Docker Official Images"

The image list:

Downloading an Ubuntu Container

  • Docker or Docker Desktop must be installed onto the computer for the following steps to work. Docker and Docker Desktop must be currently running while running the following steps.

  • Open a CLI tool

  • Type "docker" and press enter afterward to see if it is installed on the machine

docker

If Docker is installed, an output down below to use many Docker commands should be received:

  • Any existing docker image can be pulled by using:
docker pull name:tag

By specifying the name of the image, that image will be pulled and the tag is the version of that particular image. If the tag is not specified, the latest version of that image will always be pulled. To pull the Ubuntu image the following command is:

docker pull ubuntu:latest

To see if the image is on the computer, input the following command:

docker images

  • "docker images" shows the current existing images that were downloaded or built onto the computer. If the Ubuntu image was downloaded, it should be specified that it is there

  • By having the Ubuntu image, it is possible to run the image and make a container from it, which gives access to the Ubuntu operating system. Running the image is done by:

      docker run -i -name=name_of_container -t ubuntu /bin/bash
    

  • If successful, all commands will be executed within the container root space

  • When creating a new container from any operating system, a good precaution is to always update it

      apt update
    

    Cleaning Up

  • To leave the container, type:

      exit
    

  • To delete the container, go to Dockerhub and press the trash bin icon

  • To delete the image, use the following command:

      docker rmi -f ubuntu
    

  • ubuntu is the name of the image. Can also specify the image_ID instead to delete the image