How to Install Docker on Ubuntu

Now, before you start rolling your eyes at me for being a basic noob who doesn’t understand the intricacies of containerization and orchestration, let me just say this: I get it. But hear me out!

To start, let’s make sure we have all the necessary tools installed on our system. If you don’t already have Ubuntu (or any other Linux distro) running, go ahead and download a copy from their website or use your favorite virtualization software to create a new VM with it.

Once you’re up and running, open up your terminal window and type the following command:


# This script updates and upgrades the system by using the apt-get command.
# The sudo command is used to run the command as a superuser, allowing for system changes.

sudo apt-get update # This command updates the list of available packages and their versions.
&& # This is a logical operator that allows for multiple commands to be executed in one line.
sudo apt-get upgrade -y # This command upgrades all installed packages to their latest versions, with the -y flag automatically answering yes to any prompts.

# The && operator ensures that the second command is only executed if the first command is successful.
# The -y flag is used to bypass any prompts that may require user input, allowing for a smooth and uninterrupted upgrade process.

This will update your package list and install any available updates on your system. Trust me, it’s worth doing this before proceeding with anything else!

Now that we have our base system up to date, let’s move on to the fun part: installing Docker itself. To do this, simply run the following command in your terminal window:

# Install Docker on the system
sudo apt-get install docker.io -y # Use sudo to run the command as root user, -y flag automatically confirms any prompts during installation

# Update the system before proceeding
sudo apt-get update # Update the list of available packages
sudo apt-get upgrade -y # Upgrade any outdated packages, -y flag automatically confirms any prompts during upgrade

This will download and install the latest version of Docker from their official repository. If you’re feeling adventurous (or if you have a specific reason for wanting to use an older or newer version), feel free to adjust the package name accordingly.

Once Docker is installed, we can start using it right away! To do this, simply open up another terminal window and type:


// This code script is used to run the "hello-world" image in Docker.
// It is important to have Docker installed before running this script.

// The "docker run" command is used to run a Docker container.
// In this case, we are running the "hello-world" image.

// The "hello-world" image is a simple image that prints a message when run.

// To run this script, open a terminal window and type the following command:

docker run hello-world

// This will start the Docker container and print the message "Hello from Docker!".

// If the "hello-world" image is not already downloaded, Docker will automatically download it before running the container.

This will download a pre-built image from Docker Hub (their official repository) and run it in a new container. If everything goes according to plan, you should see something like this:


# This script downloads a pre-built image from Docker Hub and runs it in a new container.
# If everything goes according to plan, you should see a "Hello from Docker!" message.

# Pull the latest version of the "hello-world" image from the official Docker repository.
docker pull hello-world:latest

# Run the "hello-world" image in a new container.
docker run hello-world

# The following code segment checks if the image was found locally and pulls it from the repository if not.
# It also displays the status of the download and the image's digest.
docker pull library/hello-world

# This code segment displays the "Hello from Docker!" message, indicating a successful installation.
echo "Hello from Docker!"


echo "This message shows that your installation appears to be working correctly."

Congratulations, you’ve just run your first container using Docker on Ubuntu! From here, the sky’s the limit you can use Docker to build and deploy applications in a variety of different environments (including production), orchestrate them with tools like Kubernetes or Swarm, and much more.

So what are you waiting for? Go ahead and give it a try! And if you have any questions or feedback, feel free to leave a comment below I’d love to hear from you!

SICORPS