# Docker - Hands-on

Before going ahead with installing and playing around with Docker, let’s have a quick recap of the significant differences between Virtual Machines and Containers.

**Virtual Machines**

Virtual Machines emulate an entire computer, including its own operating system, on top of a physical server. They run on a hypervisor, which allows multiple VMs to operate on the same physical machine.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732470295471/1eb036e6-a43d-4580-80d3-34f476ea6a33.png align="center")

**Containers**

Containers are lightweight, standalone units of software that include everything an application needs to run: code, libraries, dependencies, and configuration files. They share the host operating system's kernel, making them highly efficient and fast to start.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732470400938/ca3e2d0c-3443-4343-b020-a0e9b5f74064.png align="center")

**Docker**

Docker is one of the most popular container runtimes, making it simple to create, deploy, and run applications in containers.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732470573042/dcdee26c-7a50-4c22-8d8f-acd62cc0bcec.png align="center")

Here’s a step-by-step guide to install **Docker on Ubuntu** and test it with a container.

Ensure your system is up-to-date before installing Docker.

```plaintext
sudo apt update
sudo apt upgrade -y
```

Docker requires certain prerequisites. Install them using the following commands:

```plaintext
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
```

Add the Docker GPG key to verify its packages:

```plaintext
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```

Add the Docker repository to your system:

```plaintext
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```

Update the APT package index and install Docker:4

```plaintext
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
```

Ensure Docker is installed correctly:

```plaintext
sudo docker --version
```

Run the `hello-world` container to test your Docker installation:

```plaintext
sudo docker run hello-world
```

To run Docker without `sudo`, add your user to the Docker group:

```plaintext
sudo usermod -aG docker $USER
```

Then, log out and back in for the changes to take effect.

Understanding the distinction between containers and virtual machines can help you choose the right technology. While containers are ideal for lightweight, cloud-native applications, virtual machines provide robust isolation and flexibility for diverse workloads.
