Skip to main content

Linux Install Docker

·470 words·3 mins
lab1918
Author
lab1918

To install Docker on a Linux system, you’ll need to follow a set of steps that vary slightly depending on the distribution of Linux you’re using. Below, I’ll outline the general process for installing Docker on Ubuntu, which is one of the most common Linux distributions. If you’re using a different distribution (like CentOS, Fedora, or Debian), the steps will be similar but might require some adjustments.

Installing Docker on Ubuntu
#

Step 1: Update the Package Database
#

First, update your existing list of packages:

sudo apt update

Step 2: Install Prerequisite Packages
#

Next, install a few prerequisite packages which let apt use packages over HTTPS:

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

Step 3: Add the Docker Repository
#

Then, add the GPG key for the official Docker repository to your system:

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

Add the Docker repository to APT sources:

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

Step 4: Install Docker
#

Update your package database with the Docker packages from the newly added repo:

sudo apt update

Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:

apt-cache policy docker-ce

You’ll see output like this, although the version number for Docker may be different:

docker-ce:
  Installed: (none)
  Candidate: 5:19.03.9~3-0~ubuntu-$(lsb_release -cs)
  Version table:
     5:19.03.9~3-0~ubuntu-$(lsb_release -cs) 500
        500 https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable amd64 Packages

Finally, install Docker:

sudo apt install docker-ce

Step 5: Start Docker and Enable it to Run at Boot
#

Start the Docker service:

sudo systemctl start docker

Enable Docker to start at boot:

sudo systemctl enable docker

Step 6: Verify Docker Installation
#

To verify that Docker has been installed successfully and is running, you can run the Docker hello world image:

sudo docker run hello-world

This command downloads a test image and runs it in a container. If the container runs successfully, it will print an informational message and exit.

Step 7: Using Docker without Sudo (Optional)
#

By default, running the docker command requires administrator privileges. To run Docker commands as a non-root user, you should add your user to the “docker” group:

sudo usermod -aG docker ${USER}

To apply the new group membership, log out of the server and back in, or type the following:

su - ${USER}

You will be prompted to enter your user’s password to continue.

Confirming that Docker is Working Properly
#

Check the version of Docker:

docker --version

Or get more detailed information:

docker info

Notes:
#

  • These instructions are for Ubuntu. The process for other distributions will be similar but might require different commands for managing packages.
  • Always ensure that your system is up to date and has the latest security patches installed.
  • For other Linux distributions, you can find specific installation instructions in the Docker documentation: Install Docker Engine.