Skip to main content

Docker - Installation

Docker Installation Guide

Docker is a strong tool that helps us automate how we deploy applications in light and portable containers. Knowing how to install Docker is very important for anyone who wants to make their development work better and manage applications easily. In this chapter, we will look at how to install Docker step-by-step on different operating systems. We will make sure we have the right setup and settings for a good installation.

By the end of this guide, we will know how to install Docker on Windows, macOS, and Linux systems like Ubuntu and CentOS. We will also talk about what we need to do after installation and how to check if Docker is installed correctly. Whether we are new to Docker or want to improve our skills, this chapter will give us useful information and easy examples to help us start.

For more about Docker, check out what is Docker, Docker images, and Docker containers.

Prerequisites for Docker Installation

Before we start with Docker installation, we need to make sure our system has some requirements. This helps us to set up Docker easily. Here is what we need to check:

  1. Operating System: Docker works with different operating systems like Windows, macOS, and some Linux versions. We should check if our OS version is good:

    • Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or newer)
    • macOS 10.14 or newer
    • Linux versions: Ubuntu 20.04+, CentOS 7+, Debian 9+, and more
  2. Hardware Requirements:

    • We need at least 4GB of RAM (8GB or more is better)
    • We should enable virtualization support in the BIOS. This is for Windows and macOS users.
  3. Software Dependencies:

    • If we use Linux, we must have curl, apt (for Ubuntu), or yum (for CentOS) installed.
  4. Administrative Privileges: We need to have admin or root access to install Docker.

  5. Network Access: We must make sure our machine can connect to the internet to download Docker packages.

When we check these requirements, we can go ahead with the Docker installation. For more information about Docker containers and Docker images, we can look at the linked articles.

Choosing the Right Docker Edition

When we think about installing Docker, it is very important to pick the right Docker edition. This choice helps us meet our specific needs and our work environment. Docker has a few editions. The main ones are Docker Desktop and Docker Engine. Each one serves different purposes.

  1. Docker Desktop: This one is great for developers who use Windows or macOS. It has a user-friendly interface. It also works well with our development tools. This makes it easy for us to manage images and containers. Plus, it supports Kubernetes. This gives us a complete setup for local development.

  2. Docker Engine: This is a lightweight and open-source tool for containerization. It is best for production environments. It works on Linux servers and is good for deploying applications at scale. We can also use Docker Engine on Windows and macOS, but it does not have the full desktop features.

  3. Docker Hub vs. Docker Registry: Docker Hub is a public place for sharing images. On the other hand, Docker Registry lets us host private images. We should choose based on how private our project needs to be.

  4. Enterprise Edition: For companies that need better security, management, and support, Docker has an Enterprise Edition.

For more details on Docker Images and Docker Containers, we can check out the articles. Knowing these options helps us make a good choice when we install Docker.

Installing Docker on Windows

To install Docker on Windows, we can follow these easy steps to set up our Docker environment.

  1. System Requirements: First, check that your Windows version is Windows 10 (64-bit Pro, Enterprise, or Education) or Windows 11. We should also enable the WSL 2 feature and make sure that virtualization is on in the BIOS.

  2. Download Docker Desktop: Next, we go to the official Docker website and download the Docker Desktop installer for Windows.

  3. Run the Installer: Now we run the installer we just downloaded. It will ask us to enable WSL 2 and install the Docker WSL 2 backend. Let’s follow the instructions and accept the license agreement.

  4. Complete Installation: After finishing the installation, we can launch Docker Desktop. We might need to log in with a Docker Hub account. If we do not have an account, we can create one during the setup.

  5. Verify Installation: To check if Docker is installed correctly, we can open a command prompt or PowerShell. Then we run this command:

    docker --version

This command will show us the version of Docker that is installed.

Once we finish the installation, we can start making and managing our Docker containers. For more info on Docker containers and Docker images, we can check those links. For a full overview, we can refer to What is Docker.

Installing Docker on macOS

We can install Docker on macOS by following these simple steps. Docker is a great tool for building, shipping, and running apps in containers.

  1. Download Docker Desktop: Go to the Docker Desktop for Mac page. Download the latest version.

  2. Install Docker Desktop:

    • Open the .dmg file you downloaded. Drag the Docker icon to the Applications folder.
    • Now, open Docker from the Applications folder.
  3. Grant Necessary Permissions: When we first open Docker, it will ask for permissions. It needs access to the network and file sharing. We should allow this for it to work well.

  4. Start Docker: The Docker icon will show up in the macOS menu bar. Click on it and choose “Start Docker”.

  5. Verify Installation: Open Terminal and type this command:

    docker --version

    This command checks if Docker is installed correctly.

  6. Configuration: We can change Docker settings by clicking the Docker icon in the menu bar and selecting “Preferences”.

Now that we have Docker installed on macOS, we can begin to create and manage Docker containers. For more details about Docker, check this guide.

Installing Docker on Linux (Ubuntu)

We can install Docker on Ubuntu easily. Just follow these steps for a good installation on your system.

  1. Update Package Index: First, we need to update the list of packages.

    sudo apt update
  2. Install Required Packages: We should install some packages. This helps apt use packages over HTTPS.

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
  3. Add Docker’s Official GPG Key: We will import Docker’s GPG key. This key is for checking packages.

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. Set up the Stable Repository: Now we add the Docker repository to our APT sources.

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. Update Package Index Again: We need to update the package index again to include Docker packages.

    sudo apt update
  6. Install Docker: Now we can install the latest version of Docker CE (Community Edition).

    sudo apt install docker-ce
  7. Verify Docker Installation: Finally, we check if Docker is installed correctly.

    sudo docker run hello-world

For more info about Docker containers and Docker images, look at the links. Following these steps will help us install Docker on Ubuntu. This way we can use the power of Docker for our applications.

Installing Docker on Linux (CentOS)

To install Docker on CentOS, we can follow these steps. This guide helps us install Docker on CentOS 7 and later versions.

  1. Update the System
    First, we update our CentOS system to get the latest package versions:

    sudo yum update -y
  2. Install Required Packages
    Next, we need to install some packages so that yum can use a repository over HTTPS:

    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  3. Set Up the Stable Repository
    Now, we add the Docker repository to our system:

    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  4. Install Docker
    We can install Docker Community Edition with this command:

    sudo yum install docker-ce -y
  5. Start and Enable Docker
    After that, we start the Docker service. We also enable it to run when the system starts:

    sudo systemctl start docker
    sudo systemctl enable docker
  6. Verify Docker Installation
    To check if Docker is installed correctly, we run:

    sudo docker --version

For more information about Docker, we can check out what is Docker. We can also learn about Docker images and Docker containers. By following these steps, we can install Docker on CentOS. This will help us use containerization for our applications.

Configuring Docker Post-Installation

After we install Docker, we need to configure it. This helps Docker work well and keep it safe. Here are some important settings we should think about:

  1. Manage Docker as a Non-Root User: By default, Docker needs root access. To manage Docker without root, we can do these steps:

    sudo groupadd docker
    sudo usermod -aG docker $USER

    After we run these commands, we should log out and log back in. This will make the changes work.

  2. Configure Docker Daemon Options: We can set up the Docker daemon using the /etc/docker/daemon.json file. Here is a simple example:

    {
      "log-driver": "json-file",
      "storage-driver": "overlay2",
      "insecure-registries": ["myregistry.local:5000"]
    }
  3. Enable Docker to Start on Boot: We want Docker to start automatically when our system turns on. To do this, we can run:

    sudo systemctl enable docker
  4. Configure Firewall Rules: If we have a firewall on our server, we might need to let traffic through on Docker’s default ports like 80 and 443. We can use this command for a basic setup:

    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
  5. Set Up Docker Logging: By default, Docker logs are in /var/lib/docker/containers/<container-id>/<container-id>-json.log. We can set up logging drivers in the daemon.json to manage logs better.

These settings help improve our Docker installation. They also make it safer and faster. For more understanding of Docker, we can visit What is Docker.

Starting and Stopping Docker Service

We need to know how to start and stop the Docker service. This is important to manage Docker well. Docker runs in the background on our system. We can control it with command-line interface (CLI) commands.

Starting Docker Service

To start the Docker service on different operating systems, we can use these commands:

  • On Linux (Systemd-based systems like Ubuntu and CentOS):

    sudo systemctl start docker
  • On macOS and Windows (Docker Desktop):
    The service starts by itself when we open Docker Desktop. We can also manage the service in the application settings.

Stopping Docker Service

To stop the Docker service, we can run these commands:

  • On Linux:

    sudo systemctl stop docker
  • On macOS and Windows:
    We can stop the service from the Docker Desktop app by clicking “Quit Docker Desktop” in the menu.

Checking the Status

To check if Docker is running, we can use:

sudo systemctl status docker

Knowing how to start and stop the Docker service is important for managing our Docker environment. For more information about Docker, we can learn about Docker containers and Docker images.

Verifying Docker Installation

After we finish the Docker installation, we need to check if Docker is installed right and working well. This helps us know that our system can run apps using Docker containers.

  1. Check Docker Version: We can check the installed Docker version by running this command in our terminal or command prompt:

    docker --version

    This command should show us the version of Docker we have. This means the installation was successful.

  2. Run the Hello World Container: A good way to check our Docker installation is to run a test container. We can use this command:

    docker run hello-world

    If Docker is working right, we will see a message telling us that Docker is working and our installation is good.

  3. List Docker Containers: We can also check if Docker can manage containers by listing them:

    docker ps -a

    This command will show us all containers on our system. This confirms that Docker can work with them well.

If we have any problems while checking, we can look at the Docker documentation for help. Verifying Docker installation is an important step for a smooth experience with Docker containers.

Docker - Installation - Full Example

In this guide, we will show you how to install Docker on an Ubuntu system. Ubuntu is a very popular choice for Docker development.

  1. Update Your System: First, we need to update the package index.

    sudo apt-get update
  2. Install Required Packages: Next, we install some packages. These help apt to work with packages over HTTPS.

    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
  3. Add Docker’s Official GPG Key: We need to add a key. This key helps us check that Docker packages are safe.

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. Set Up the Stable Repository: Now we add the Docker repository to our APT sources.

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. Install Docker: After that, we update the package index again. Then, we can install Docker CE (Community Edition).

    sudo apt-get update
    sudo apt-get install docker-ce
  6. Verify Docker Installation: Now we check if Docker is installed and running well.

    sudo systemctl status docker
  7. Run a Test Container: Finally, we run a simple Docker container to test our installation.

    sudo docker run hello-world

This guide shows us how to install Docker completely on Ubuntu. For more information about Docker and its features, we can check what is Docker. We can also look at Docker images and Docker containers to learn more.

Conclusion

In this guide about Docker - Installation, we talked about the basic needs for installing Docker. We looked at the different Docker editions. We also gave clear steps for installing Docker on Windows, macOS, and Linux like Ubuntu and CentOS.

Also, we explained how to configure Docker after installation. We talked about managing services too. Knowing Docker and its parts, like Docker images and Docker containers, helps us improve our development work.

If we want to learn more, we can check what Docker is.

Comments