Community for developers to learn, share their programming knowledge. Register!
Start Learning Docker

Installing Docker: Step-by-Step Guide


Welcome to this Installing Docker: Step-by-Step Guide! In this article, you can get training on the installation process of Docker, a powerful tool that has transformed application development and deployment through containerization. Whether you’re an intermediate developer looking to expand your toolkit or a seasoned professional wanting to refine your setup, this guide will walk you through installing Docker on various platforms, ensuring you have a solid foundation to work with.

Before we dive into the installation process, it’s essential to understand what Docker is and why it’s beneficial. Docker is an open-source platform that automates the deployment of applications within lightweight containers. These containers package everything your application needs to run, including code, libraries, and dependencies, ensuring consistency across different environments. With Docker, you can easily manage application dependencies and scale your applications efficiently.

Prerequisites

Before proceeding with the installation, ensure that your system meets the following prerequisites:

  • Operating System: Docker is compatible with various operating systems, including Windows, macOS, and several Linux distributions.
  • Hardware Requirements: A 64-bit processor and at least 4 GB of RAM are recommended for optimal performance.
  • Administrative Privileges: You’ll need administrative rights to install Docker on your machine.

Installing Docker on Windows

  • Download Docker Desktop for Windows: Visit the official Docker website. Click on the "Download for Windows" button to get the installer.
  • Run the Installer: Locate the downloaded installer (Docker Desktop Installer.exe) and double-click it to run. Follow the installation prompts. You may need to enable the WSL 2 feature during installation if it’s not already enabled.
  • Enable WSL 2 (if prompted): Open PowerShell as an administrator and run the following command to enable WSL with below command. Restart your computer if prompted.
wsl --install
  • Complete Docker Installation: After enabling WSL 2 and completing the installation, launch Docker Desktop from the Start menu. Docker will take a moment to initialize.
  • Verify Installation: Open a command prompt or PowerShell and run below command. You should see the installed Docker version.
docker --version

Installing Docker on Ubuntu

  • Update Your Package Index: Open a terminal and run the following command to update your package repository.
sudo apt-get update
  • Install Required Packages: Install prerequisite packages that allow apt to use packages over HTTPS.
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
  • Add Docker’s Official GPG Key: Run the command to add Docker’s official GPG key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • Set Up the Stable Repository: Add the Docker repository to your system’s software repository list.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • Update Package Index Again: Update your package index to include Docker packages.
sudo apt-get update
  • Install Docker CE (Community Edition): Finally, install Docker.
sudo apt-get install docker-ce
  • Start Docker and Enable it to Run at Boot: Start the Docker service and enable it to launch at startup.
sudo systemctl start docker
sudo systemctl enable docker

Verify Installation:  Run the following command to verify the installation.

docker --version

Installing Docker on macOS

  • Download Docker Desktop for Mac: Navigate to the official Docker website: Docker Desktop for Mac. Click on "Download for Mac" to obtain the installer.
  • Install Docker Desktop: Open the downloaded .dmg file and drag the Docker icon to your Applications folder. Launch Docker from the Applications folder.
  • Complete Initial Setup: Follow the on-screen instructions to complete the initial setup. You may need to provide your system password.
  • Verify Installation: Open Terminal and run below command. Confirm that Docker is installed and check the version using below command command.
docker --version

Post-Installation Steps

After installing Docker, you may want to perform a few additional steps to enhance your experience:

  • Manage Docker as a Non-root User: By default, Docker commands must be run with sudo. To avoid this, you can add your user to the Docker group. Log out and back in for these changes to take effect.
sudo usermod -aG docker $USER
  • Test Docker Installation: Run the following command to test your Docker installation. This command downloads a test image and runs it in a container. If everything is set up correctly, you will see a message indicating that your installation appears to be working.
docker run hello-world

Summary

In this step-by-step guide, you learned how to install Docker on various operating systems, including Windows, Ubuntu, and macOS. With Docker installed, you’re now equipped to start building, running, and managing containerized applications effectively. Docker’s powerful features will allow you to streamline your development processes and ensure consistency across environments.

Last Update: 15 Dec, 2024

Topics:
Docker