MC, 2025
Ilustracja do artykułu: How to Install Docker on Linux: A Step-by-Step Guide

How to Install Docker on Linux: A Step-by-Step Guide

If you’ve been hearing a lot about Docker lately and want to get it running on your Linux machine, you’ve come to the right place! Docker is a powerful tool that allows developers to build, ship, and run applications in containers. It's fast, efficient, and widely used in modern development. In this guide, we’ll walk you through the process of installing Docker on Linux, and show you some practical examples to help you get started.

What is Docker?

Before diving into installation, let’s take a moment to understand what Docker is and why it’s so popular in the development community. Docker is an open-source platform that automates the deployment, scaling, and management of applications in lightweight containers. Containers are isolated environments that bundle your application with everything it needs to run—like the operating system, libraries, and dependencies. This ensures that your application behaves the same no matter where it’s deployed, whether it’s on your local machine, a testing server, or in production.

Why Install Docker on Linux?

Linux is one of the most popular environments for Docker because it’s lightweight, open-source, and easily configurable. Docker was originally built for Linux, so it runs seamlessly on this platform. Whether you are working on a personal project, testing new software, or deploying applications at scale, Docker makes the process more efficient and portable. Installing Docker on Linux is straightforward, and once it's up and running, you’ll have access to an ecosystem of powerful tools for development and deployment.

Step 1: Update Your Linux System

Before installing Docker, it’s a good idea to update your Linux system to ensure you have the latest software packages. This will help avoid any conflicts during installation. To update your system, run the following commands:

sudo apt-get update
sudo apt-get upgrade

These commands will refresh your package list and install any available updates. Once the updates are finished, you’re ready for the next step!

Step 2: Install Required Dependencies

Docker requires some dependencies to function properly. You’ll need to install a few essential packages before proceeding. Run the following command to install the required dependencies on your system:

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

This command installs the necessary tools for Docker to securely interact with repositories and manage packages. Once the dependencies are installed, you’re all set to move forward!

Step 3: Add Docker’s Official GPG Key

Docker uses a cryptographic key to verify the authenticity of packages from its official repository. To add the key to your system, run this command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

This command fetches Docker's GPG key and adds it to your list of trusted keys. This is an important security step that ensures the packages you install are from the official Docker repository and not a malicious source.

Step 4: Add Docker Repository

Now that you’ve added the GPG key, the next step is to add Docker’s repository to your system’s list of software sources. Run the following command to add the Docker repository:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

This command configures your package manager to retrieve Docker packages from the official Docker repository. The $(lsb_release -cs) part automatically detects your Linux distribution version, making it easy to set up.

Step 5: Install Docker

With the repository added, you can now install Docker. Run the following command to install the Docker Engine:

sudo apt-get update
sudo apt-get install docker-ce

This will install Docker Community Edition (CE), the free version of Docker. Once the installation is complete, Docker should be up and running on your Linux machine. You can verify that Docker was installed successfully by running:

sudo docker --version

This will display the Docker version installed on your system. If you see the version number, congratulations—you’ve installed Docker!

Step 6: Start Docker and Enable It to Run on Boot

By default, Docker may not start automatically after installation. To start Docker manually, run the following command:

sudo systemctl start docker

If you want Docker to start automatically whenever your system boots up, you can enable it with this command:

sudo systemctl enable docker

This ensures that Docker runs in the background as soon as you start your Linux machine. Now Docker will be ready to use without any extra steps.

Step 7: Verify Docker Installation

Once Docker is installed and running, it’s important to check that everything is working properly. You can verify the installation by running the following command:

sudo docker run hello-world

This command will download a test image from Docker’s repository and run it in a container. If everything is set up correctly, you should see a “Hello from Docker!” message. This confirms that Docker is correctly installed and functional on your system.

Docker Commands for Beginners

Now that you’ve installed Docker, let’s go over some basic Docker commands that will help you manage containers and images. Here are a few commands you’ll use frequently:

  • docker run – Runs a container from a specified image. Example:
    docker run -it ubuntu
  • docker ps – Lists all running containers. Example:
    docker ps
  • docker images – Lists all Docker images on your system. Example:
    docker images
  • docker stop – Stops a running container. Example:
    docker stop container_name
  • docker rm – Removes a container. Example:
    docker rm container_name

These commands will help you manage containers and images, the building blocks of Docker. As you get more familiar with Docker, you can start exploring more advanced commands and configurations.

Conclusion

Installing Docker on Linux is a straightforward process that opens up a world of possibilities for development and deployment. Whether you're building applications, testing software, or deploying scalable systems, Docker’s containerization technology will help make your workflows more efficient and consistent. With the steps outlined in this guide, you should be able to get Docker up and running in no time. Now that Docker is installed on your Linux machine, it’s time to explore the many ways it can improve your development environment. Happy Dockerizing!

Komentarze (0) - Nikt jeszcze nie komentował - bądź pierwszy!

Imię:
Treść: