the tech lab!

Install Docker and Elevate Your Dev Environment

Install Docker
Get to know how to install Docker and start using this ultra-powerful tool for Containerization. From installation to running your very first container is all covered in this step by step tutorial. Great for both beginner and pro!

Today, we’re going to talk about Docker—a great tool that changed how we build, ship, and even run applications. Docker has become the go-to tool for every developer and a must-have tool for any IT professional. The easiness of deploying and managing applications has made Docker technology a basic and core one in the cloud-based environments that are operating nowadays.

I will explain what Docker is, how it is different from traditional Virtual Machines, how to install Docker and what has really made a change in the game about Docker in the world of containerization in this article.



Virtual Machines

Before learning Docker, it’s essential to know what a virtual machine is and how it works. A Virtual Machine or VM is software emulating physical hardware, which allows many operating systems to exist on one physical machine.

A virtual machine runs on a hypervisor, which is a piece of software that enables multiple operating systems to share the same physical hardware. This allows for better resource utilization. However, each VM requires its own operating system, which can consume significant resources.

  • Dedicated resources per VM
  • Requires hypervisor for management
  • Can run multiple OS types
  • Resource-intensive
Challenges with Virtual Machines

While VMs are powerful, they come with drawbacks:

  • High resource consumption
  • Slower boot times
  • Complex management

These challenges have led to the exploration of alternative solutions, and here comes our Docker.


What is Docker?

Imagine working on a project that requires multiple software environments. Now, setting up different environments is hard, eh? Exactly, Docker makes life easy!

Docker is an open-source platform that makes it possible to build lightweight, standalone executables through containerization. Each such container includes all that is necessary to run an application: code, runtime, system tools, libraries, and settings.


Pros of Using Docker
  1. Consistency: Docker ensures that your software will run the same way in any environment, reducing the classic “it works on my machine” problem.
  2. Isolation: Each container operates independently, making it easier to manage dependencies and prevent conflicts.
  3. Scalability: Docker makes it simple to scale applications, whether you’re running one container or a thousand.
  4. Efficiency: Containers are lightweight and start quickly, saving both time and resources.

How does Docker Work?

Docker operates on a single operating system and uses the host OS’s kernel to run multiple isolated applications or services called a container, that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. Here’s a breakdown of how Docker achieves this:

  1. Docker Images:
    • A Docker image is a snapshot of your application at a specific point in time. It includes everything your application needs to run, like code, runtime, libraries, environment variables, and configuration files. Docker images are read-only templates used to create containers.
  2. Docker Containers:
    • Containers are the executable instances of Docker images. They are isolated, meaning they have their own filesystem, memory, and network interfaces, but they share the kernel with the host OS. Containers are lightweight because they share the host’s kernel, making them faster and less resource-intensive compared to virtual machines.
  3. Docker Engine:
    • The Docker Engine is the runtime that enables containers to be built, run, and managed. It uses a client-server architecture, where the Docker client talks to the Docker daemon, which handles the heavy lifting of building, running, and distributing Docker containers.
  4. Docker Registry:
    • Docker Hub is the default public registry where Docker images are stored and shared. You can pull images from Docker Hub to use on your local machine, or push your images to Docker Hub to share with others. Private registries can also be set up for more control over image distribution.

How to install Docker

Now that you have understood what Docker is and How it works. Lets get going with how to install Docker. Docker is a cross-platform so it is supported in Windows, Mac, and Linux. So, I will go through the installation process of all three.

Install Docker in Linux

Step 1: Update your repositories

  • To update your repositories, open up your terminal and run the following command:
    • sudo apt-get update

Step 2: Install Docker

  • To install docker, first we need Docker’s official GPG key, to get that run the following command:
    • sudo apt-get update
    • sudo apt-get install ca-certificates curl
    • sudo install -m 0755 -d /etc/apt/keyrings
    • sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    • sudo chmod a+r /etc/apt/keyrings/docker.asc
install docker - linux
  • Now we need to add Docker Repository:
    • echo \ “deb [arch=$(dpkg –print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo “$VERSION_CODENAME”) stable” | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
      • If you are using Ubuntu or Ubuntu based distros, you need to replace VERSION_CODENAME to UBUNTU_CODENAME
install docker - linux
  • Now, update the package index again and install Docker:
    • sudo apt-get update
    • sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
install docker - linux
install docker - linux

Step 3: Verify that the Docker installation

  • You can verify the installation is successful by running the hello-world image
    • sudo docker run hello-world
      • This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
install docker - linux

Install Docker on Windows

Step 1: Download Docker Desktop

  • To install Docker in Windows, you have to download Docker Desktop. Head over to Docker Hub to download it.

Step 2: Run the Installer

  • Run the downloaded installer and follow the on-screen prompts. Make sure you enable WSL2 feature for better performance. More on WSL here.

Step 3: Complete the setup

  • After the installation is complete, restart the system and then Docker Desktop will start automatically. You might need to log with your Docker ID, or you can continue without signing.

Install Docker on Mac

Installing Docker on macOS

1. Get Docker Desktop:

2. Install Docker Desktop:

  • Run the downloaded .dmg file you just downloaded, dragging the Docker icon into your Applications folder, and open Docker.

3. Launch Docker:

  • Launch Docker from the Applications. You may need to grant permissions and log in with your Docker ID.

How to use Docker

Now, with Docker installed on your system, its time to dip your hands in the river and start using it. Here’s a simple guide for it.

Running Your First Container
  1. Pull an Image:
    • Images are the base for containers. Let’s start with a simple hello-world image:
      • docker pull hello-world
  2. Run the Container:
    • Now, run the container from the image:
      • docker run hello-world
    • You should see a message from Docker confirming that everything is working.

Managing Containers
  1. List Running Containers:
    • To see all running containers, use:
      • docker ps
  2. List All Containers:
    • To see all containers, including stopped ones:
      • docker ps -a
  3. Stop a Container:
    • To stop a running container, use:
      • docker stop [container_id]
  4. Remove a Container:
    • To remove a container:
      • docker rm [container_id]

Conclusion

And there you go, folks! Installing Docker and using it really isn’t that hard. No matter if it is development, run, or even dependency management, Docker simplifies the task at all levels and makes everything much more efficient. So go for it and see how it will revolutionize your workflow.

And remember, if you ever feel stuck, the Docker Community is vast and super helpful. Don’t hesitate to reach out for support.

Scroll to Top