How To Install Docker on Ubuntu 18.04 & 16.04 LTS

How To Install Docker on Ubuntu 18.04 & 16.04 LTS

How to Install Docker on Ubuntu 18.04 & 16.04 LTS

Prerequisites

  • A 64-bit version of Ubuntu 18.04 or 16.04.

  • A user account with sudo privileges.

  • A stable internet connection.

Step 1: Uninstall Old Versions (if any)

Before installing Docker, remove any older versions to avoid conflicts:

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

Step 2: Set Up Docker’s Official Repository

  1. Update the package index:

    sudo apt-get update

  1. Install required packages:

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

  1. Add Docker’s official GPG key:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg

  1. Set up the stable repository:

    For Ubuntu 18.04:

    echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

For Ubuntu 16.04:

echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu xenial stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 3: Install Docker Engine

  1. Update the package index again:

    sudo apt-get update

  1. Install Docker CE (Community Edition):

    sudo apt-get install docker-ce docker-ce-cli containerd.io

Step 4: Start and Enable Docker

  1. Start Docker:

    sudo systemctl start docker

  1. Enable Docker to start on boot:

    sudo systemctl enable docker

Step 5: Verify Docker Installation

Run the following command to check if Docker is installed correctly:

sudo docker run hello-world

If Docker is installed correctly, you'll see a message saying:

Hello from Docker! This message shows that your installation appears to be working correctly.

Step 6: Manage Docker as a Non-root User (Optional)

To run Docker commands without sudo, add your user to the Docker group:

sudo usermod -aG docker $USER

Note: Log out and log back in for the group changes to take effect.

Step 7: Test Docker Without sudo

After logging back in, test Docker without using sudo:

docker run hello-world

Step 8: Update Docker (Optional)

To keep Docker up to date, periodically run:

sudo apt-get update sudo apt-get upgrade docker-ce docker-ce-cli containerd.io

Step 9: Uninstall Docker (if needed)

To remove Docker from your system:

sudo apt-get purge docker-ce docker-ce-cli containerd.io sudo rm -rf /var/lib/docker

For more detailed information, you can refer to the official Docker documentation:

If you need assistance with Docker Compose or Docker Desktop, feel free to ask!

Souy Soeng

Souy Soeng

Hi there šŸ‘‹, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
šŸ‘Æ I’m looking to collaborate on open-source PHP & JavaScript projects
šŸ’¬ Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close