65.9K
CodeProject is changing. Read more.
Home

A Fresh Start: Setting Up Ubuntu with Docker

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

May 11, 2023

CPOL

2 min read

viewsIcon

6032

Learn how to set up a fresh Ubuntu installation with Docker, enabling you to leverage the power of containerization for efficient development and deployment.

Introduction

Ubuntu is one of the most popular Linux distributions, renowned for its stability, versatility, and user-friendly interface. When combined with Docker, an open-source platform for containerization, Ubuntu becomes an incredibly powerful development and deployment environment. In this article, we will guide you through the process of setting up a fresh Ubuntu installation with Docker, enabling you to leverage the benefits of containerization for your projects.

Step 1: Installing Ubuntu

The first step is to install Ubuntu on your machine. You can download the latest Ubuntu ISO file from the official website (https://ubuntu.com/download). Once you have the ISO, create a bootable USB drive or use a virtual machine to install Ubuntu. Follow the installation wizard, select your preferences, and complete the installation process.

Step 2: Updating Ubuntu

After the installation, it's crucial to update Ubuntu to ensure you have the latest security patches and software updates. Open the Terminal and execute the following commands:

sudo apt update
sudo apt upgrade 

Enter your password when prompted and allow the updates to install. This process might take some time, depending on your internet speed and the number of updates available.

Step 3: Installing Docker

Now that Ubuntu is up to date, we can proceed with installing Docker. Docker provides a convenient way to package, distribute, and run applications within containers, ensuring consistency across different environments. Open the Terminal and execute the following commands:

  1. Install the required packages to allow apt to use a repository over HTTPS:
    sudo apt install apt-transport-https ca-certificates curl software-properties-common 
  2. Import the Docker GPG key to ensure the authenticity of the software package:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 
         sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 
  3. Add the Docker repository:
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] 
          https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | 
          sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  4. Update the apt package index and install Docker:
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io
  5. Verify that Docker is installed correctly by running a simple "hello-world" container:
    sudo docker run hello-world

Step 4: Managing Docker as a Non-root User

By default, Docker requires root privileges to execute Docker commands. However, it is recommended to manage Docker as a non-root user for security reasons. To achieve this, you can add your user to the "docker" group:

  1. Create the "docker" group (if it doesn't already exist):
    sudo groupadd docker
  2. Add your user to the "docker" group:
    sudo usermod -aG docker $USER
  3. Log out and log back in to apply the group changes.

    After completing these steps, you should be able to use Docker without sudo by simply running Docker commands in the Terminal.

Step 5: Testing Docker Setup

To confirm that your Docker setup is working correctly, you can run a few additional tests:

  1. Check the Docker version:
    docker --version
  2. Pull and run a popular Docker image, such as "nginx":
    docker run -d -p 80:80 nginx
  3. Open your web browser and navigate to http://localhost. If everything is working correctly, you should see the default Nginx page.

Congratulations!!

History

  • 11th May, 2023: Initial version