How to set up Docker on Linux

Master Docker setup on Linux with this step-by-step guide. Includes installation, user configuration, and best practices.
Try the NVMe cloud.

Start your 7-day free trial with no commitment. Explore freely and continue if it’s right for you.

Docker has become a go-to tool for developers and system administrators who want to containerize applications, streamline development, and simplify deployment. If you’re running Linux, setting up Docker is straightforward – but it’s important to do it correctly to ensure everything runs smoothly.

This guide will walk you through the process step by step, ensuring you don’t miss a thing. If you’re looking for a quick and easy setup, explore the Docker app available on our marketplace.

Why use Docker on Linux?

Docker allows you to create lightweight, portable containers for your applications. By running Docker on Linux, you take advantage of:

  • Native performance (Linux is Docker’s native platform).
  • Compatibility with a wide range of images and tools.
  • Seamless integration with modern DevOps workflows.

Now, let’s get started with setting it up.

Prerequisites

Before installing Docker, make sure your system meets these requirements:

1. Supported Linux distributions:

  • Ubuntu (16.04 or newer)
  • Debian (Stretch or newer)
  • CentOS (7 or newer)
  • Fedora (35 or newer)
  • Other distributions with equivalent package managers.

2. Required packages:

  • Ensure your system has curl or wget installed.
  • A user account with sudo privileges.

3. Up-to-date system:

Run the following commands to update your system packages:

				
					sudo apt update && sudo apt upgrade -y   # For Ubuntu/Debian
sudo yum update -y                        # For CentOS/Fedora
				
			

Step 1: Install Docker

Follow these steps to install Docker on your Linux system. We’ll cover Ubuntu/Debian and CentOS/Fedora separately for clarity.

For Ubuntu/Debian

1. Uninstall old versions (if any):

				
					sudo apt remove docker docker-engine docker.io containerd runc
				
			

2. Set up the repository:

				
					sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
				
			

3. Install Docker Engine:

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

4. Verify installation:

				
					sudo docker --version
				
			

For CentOS/Fedora

1. Uninstall old versions:

				
					sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
				
			

2. Set up the repository:

				
					sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
				
			

3. Install Docker Engine:

				
					sudo yum install -y docker-ce docker-ce-cli containerd.io
				
			

4. Start and enable Docker:

				
					sudo systemctl start docker
sudo systemctl enable docker
				
			

5. Verify installation:

				
					sudo docker --version
				
			

Step 2: Add your user to the Docker group

By default, Docker requires sudo to run. To avoid typing sudo every time, add your user to the Docker group:

1. Add your user:

				
					sudo usermod -aG docker $USER
				
			

2. Log out and back in, or use:

				
					newgrp docker
				
			

3. Test Docker without sudo:

				
					docker run hello-world
				
			

Step 3: Configure Docker for optimal use

Enable Docker on startup

Ensure Docker starts automatically when your system boots:

				
					sudo systemctl enable docker
				
			

Adjust storage driver (optional)

Docker defaults to the overlay2 storage driver, which is suitable for most systems. If needed, you can configure a different driver in /etc/docker/daemon.json:

				
					{
  "storage-driver": "overlay2"
}
				
			

Configure logging (optional)

Manage log size to prevent containers from using excessive disk space:

				
					{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
				
			

Step 4: Test Docker installation

Now that Docker is installed, run a test container:

1. Pull and run the hello-world image:

				
					docker run hello-world
				
			

This confirms that Docker is running correctly.

2. Run an interactive container:

				
					docker run -it ubuntu bash
				
			

Exit the container with:

				
					exit
				
			

Conclusion

Setting up Docker on Linux is more than just running installation commands. It’s about understanding your system and configuring Docker to suit your workflow.

Whether you’re automating backups, managing container logs, or exploring advanced storage options, these steps provide a solid foundation to get started. With Docker running, you’re ready to build, deploy, and manage applications efficiently, all while taking advantage of Linux’s native performance.

Useful insights?

Help others discover this article by sharing it.